Clear Filters
Clear Filters

string array of plot colors

2 views (last 30 days)
pemfir
pemfir on 25 Dec 2012
I have a program that classifies the points, and at the time of classification i can assign different properties to the points (e.g., points in class one are all '*r' , red star, and points in class two are 'ob' , blue circle, for later plotting. Once the classification is done. I would like to plot the points. using something like this.
color = {':b',':g',':r'}; % is constructed earlier
plot([1:3], [1:3], color{:});
but i get an error, it can not handle the whole array of colors i have to do
color = {':b',':g',':r'};
for i=1:3
plot(i, i, color{i});
end
which is very slow and annoying if you have many points.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Dec 2012
plot() cannot assign colors on a per-point basis. You should use scatter() for that. If you want the points joined, then plot() first without any marker and the scatter() the markers in place.
Note that the third argument to scatter(), before the colors, is the point size.
The color argument to scatter needs to be an RGB array.
  1 Comment
pemfir
pemfir on 25 Dec 2012
Thanks a lot ! it does the job for me!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!