Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group and plot data from specific columns in matrix

Tags:

matlab

After parsing and grouping my data in matrix, I tried to scatter plot my data in matrix and got some errors. My parsed and grouped data matrix is shown as below:

a = [1.05 2.1 3.4 1; 1.06 2.2 3.6 1; 2.04 2.3 3.8 2; 2.15 2.2 4.0 2; 1.37 2.3 3.7 1;3.12 2.1 4.1 3;3.02 2.2 4.2 3;3.42 2.3 4.5 3;3.24 2.4 4.8 3]

a =

1.0500    2.1000    3.4000    1.0000
1.0600    2.2000    3.6000    1.0000
2.0400    2.3000    3.8000    2.0000
2.1500    2.2000    4.0000    2.0000
1.3700    2.3000    3.7000    1.0000
3.1200    2.1000    4.1000    3.0000
3.0200    2.2000    4.2000    3.0000
3.4200    2.3000    4.5000    3.0000
3.2400    2.4000    4.8000    3.0000

I rounded the a(:,1) values and put them in a(:,4).

The desired plot should be as shown below (I plot them in excel):

enter image description here

Basically I need to group the data according to the values in a(:,4).

I wrote the code below:

splitapply(@(x,y)plot(x,y),a(:,2),a(:,3),findgroups(a(:,4)))

The plot is shown as below:

enter image description here

How can I plot the data as shown in the first figure (plotted in excel)?

like image 473
FunkyMore Avatar asked Dec 29 '25 11:12

FunkyMore


1 Answers

You forgot to hold on. Adding some nicer plotting options:

hold on
% same thing you have but with markers!
splitapply(@(x,y)plot(x,y,'marker','.','markersize',20),a(:,2),a(:,3),findgroups(a(:,4)))
axis([2.05 2.45 0 6]) %same as excel
grid on

enter image description here

like image 96
Ander Biguri Avatar answered Dec 31 '25 04:12

Ander Biguri