필터 지우기
필터 지우기

string array of plot colors

조회 수: 2 (최근 30일)
pemfir
pemfir 2012년 12월 25일
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.

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 25일
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
pemfir
pemfir 2012년 12월 25일
Thanks a lot ! it does the job for me!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by