Error: Bad property value for color- why?

조회 수: 4 (최근 30일)
Simon
Simon 2014년 7월 3일
댓글: Simon 2014년 7월 4일
Hi, I have following error, which I don't know why it is occurring:
Error using plot
Bad property value found.
Object Name: line
Property Name: 'Color'.
I have many customized colors that I use via a cell:
cl={'w','bla','blat','w2','ora','orat','w3','sbl','sblt','w4','bgr','bgrt','w5','yel','yelt','w6','blu','blut','w7','ver','vert'};
plot([ xx fliplr(xx) xx(1)],[0 0 1 1 0],'color',cl{M{1,m-1}(q)+1},'linewidth',12)
Thanks!
  댓글 수: 2
Image Analyst
Image Analyst 2014년 7월 3일
What is the value of M{1,m-1}(q)? Try this
M{1,m-1}(q) % Spit out to command window
fprintf('M{1,m-1}(q) = %d\n', M{1,m-1}(q)); % Again as integer
Simon
Simon 2014년 7월 4일
The whole code is
for m=2:n+1;
subplot(n+1+size,1,m+size-1);
for q=1:t;
xx=[q-1,q] ;
plot([ xx fliplr(xx) xx(1)],[0 0 1 1 0],'color',cl{M{1,m-1}(q)+1},'linewidth',12)
hold on
end
hold off
end
so right now the code gets stuck at
m=2, t=12,
M{1,m-1}(q)=2, fprintf('M{1,m-1}(q) = %d\n', M{1,m-1}(q));
M{1,m-1}(q) = 2
The Idea of the whole code is this: I have n machines of which I want to show their statuses, like ON, OFF, Standby; each of the bars should have different colors for them (that's the reason for the many colors). M is a 1 x n cell containing 1 x t arrays. Those arrays contain the status of the Machines, for the first machine it is 0,1,2; the second 3,4,5 and so on. The whole thing worked fine when I just had 3 colors for every machine, which then were 0,1 or 2. (then I built in a loop so they would get higher integers for the color variation)

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

채택된 답변

Robert Cumming
Robert Cumming 2014년 7월 4일
It looks like you are passing a string into the color command and not the RGB value:
i.e. you are doing:
plot([ xx fliplr(xx) xx(1)],[0 0 1 1 0],'color',cl{M{1,m-1}(q)+1},'linewidth',12)
where cl is a string. It is not being evaluated to the RGB you want. While in theory you could "eval" the string - I would not recommend that approach.
A much better solution would be to use a matrix or cellarray containing the colors. Or you can use your current approach (using names) with a structure:
myColors.sbl=[0.35 0.7 0.9]; % skyblue
myColors.bgr=[0 0.6 0.5]; % bluish green
Then access the colors by using dynamic fieldnames:
plot([ xx fliplr(xx) xx(1)],[0 0 1 1 0],'color',myColors.(cl{M{1,m-1}(q)+1}),'linewidth',12)

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 7월 3일
Where did you get all those color names? I don't think they're ones that are recognized. Try simple things like 'r', 'y', 'k', etc. as well as 3 element arrays with values between 0 and 1, for example [.2, .3, .7].
  댓글 수: 2
Simon
Simon 2014년 7월 4일
I have defined those colors before, like:
sbl=[0.35 0.7 0.9]; % skyblue
bgr=[0 0.6 0.5]; % bluish green
that should be fine, should'nt it?
Image Analyst
Image Analyst 2014년 7월 4일
No. Because you're putting the name of the variable in there, not the variable itself. It has no idea that the string 'blat' is the name of some variable you created.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by