Identify repeated values with corresponding rows within an array and then make a scatter plot

1 visualizzazione (ultimi 30 giorni)
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
clear;
clc;
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
figure
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
scatter(x_values(1:168),y_values(1:168),'c','filled','s');% Alkanes
hold on
box on
scatter(x_values(169:243),y_values(169:243),'c','filled','^');%Branched Alkanes
scatter(x_values(244:396),y_values(244:396),'r','filled', 'd');% Cycloalkanes
scatter(x_values(397:717),y_values(397:717),'g','filled','s');%Alkenes
scatter(x_values(718:850),y_values(718:850),'g','filled', '^');% Branched Alkenes
scatter(x_values(851:913),y_values(851:913),'b','filled','d');%Cycloalkenes

Risposte (1)

Vimal Rathod
Vimal Rathod il 17 Ago 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by