I want to make a 2D plot of points with different x, y coordinates and have colors depending on a separate variable. I have make column vectors for x and y coordinates and another column containing 1 or -1. I would like to represent the points with 1 as red and -1 as blue points. I have codes as follow:(adsbygoogle = window.adsbygoogle || []).push({});

However it doesn't work. How should I modify the code? Thank you.Code (Matlab M):

x_dis=rho_rec(1:nDis,xCol,step);%x coordinates

y_dis=rho_rec(1:nDis,yCol,step); %y coordinates

bv=rho_rec(1:nDis,bvCol,step); % 1 or -1

for i=1:1:nDis

if bv(i)==1

dis_color(i,1:3)=[0 0 1]; %blue

elseif bv(i)==-1

dis_color(i,1:3)=[1 0 0]; %red

end

end

plot(x_dis,y_dis,'.','Color',dis_color(1:nDis,:))

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab How to make 2D plot of points with different colors?

Tags:

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - plot points different | Date |
---|---|

Mathematica How to get data points from plot? | May 12, 2016 |

Plotting A Set of Points in Mathematica | Jun 28, 2015 |

Sigma Plot, Non-linear regression, fitting a line to a set of points | Jan 29, 2013 |

Best way to achieve a plot of polar coordinate points for CIE L*C*H* colour system | Sep 3, 2012 |

Plot graph of different color for different points? Matlab | Mar 22, 2008 |

**Physics Forums - The Fusion of Science and Community**