tintin
tintin

Reputation: 1519

matlab plot data in a functional way

I got some data like this,

 76.09879   87.42057    1.00000
 84.43282   43.53339    1.00000
 95.86156   38.22528    0.00000
 75.01366   30.60326    0.00000
 82.30705   76.48196    1.00000
 69.36459   97.71869    1.00000
 39.53834   76.03681    0.00000
 53.97105   89.20735    1.00000
 69.07014   52.74047    1.00000
 67.94686   46.67857    0.00000
 70.66151   92.92714    1.00000
 76.97878   47.57596    1.00000
 67.37203   42.83844    0.00000

what I want to do is to plot all these points with the first as X and the second as Y, and if the third value is 0 plot with a 'ko' as parameter else use 'k+'

I wonder if I can use a functional style code like

plot(data(:,1),(:,2),%a  function to turn 0 to 'k0',1 to 'k+');

to plot the data?

ps: I use mathematica a lot, that's the reason why I am asking this kind of problem

Upvotes: 3

Views: 928

Answers (2)

Naziha ALI SAOUCHA
Naziha ALI SAOUCHA

Reputation: 19

positive = find(y==1);
negative = find(y==0);

plot(X(positive,1),X(positive,2),'k+');
plot(X(negative,1),X(negative,2),'ko');

Upvotes: 2

Simon
Simon

Reputation: 32873

No, but you can do:

plot(data(data(:,3)==1,1), data(data(:,3)==1,2), 'k+', ...
     data(data(:,3)==0,1), data(data(:,3)==0,2), 'ko')

Or this but this is uglier:

plot(data(logical(data(:,3)),1), data(logical(data(:,3)),2), 'k+', ...
     data(!logical(data(:,3)),1), data(!logical(data(:,3)),2), 'ko')

Upvotes: 1

Related Questions