Identify repeated values with corresponding rows within an array and then make a scatter plot
4 views (last 30 days)
I have many data points that are arranged by 'Fuel Class', and I need a code that identifies the fuel class and the corresponding x/y values. In the example below I skip this step since I know that the first 168 x/y values belong to the fuel class 'Alkanes', i.e. the first column of my data has 168 times the value 'Alkanes' with the corresponding x/y values in the other columns, and then 'Branched Alkanes' for the next fuels and so on. The x/y values are integers.
I need a scatter plot that identifies all x/y values within a 'Fuel Class' and then plots them with the corresponding label and color. I tried some stuff with for loops and so on but it just doesn't work :( the picture shows the desired plot.
%% Load data
data = 'fuels.xlsx';
[ndata, text, alldata] = xlsread(data,'A1:C3083');
M = ndata;
fuel_classes = text(2:end,1); % cell array
x_values = M(:,1); % double
y_values = M(:,2); % double
%% Parity Plot
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
scatter(x_values(244:396),y_values(244:396),'r','filled', 'd');% Cycloalkanes
scatter(x_values(718:850),y_values(718:850),'g','filled', '^');% Branched Alkenes
Vimal Rathod on 17 Aug 2020
You could use the "findgroups" function in matlab to find the elements indices belonging to the same group.
There is also a function called "splitapply" which you could use to take in all the values belonging to same group and apply scatter plot to it.
Refer to the below link to know more about how to use findgroups function with splitapply.