Problem with plotting with string of different color names
Problem with plotting with string of different color names
(OP)
Hello,
I am having problem with using different colors base on the the various cmd in the for loop. I apply the suggested solution provided in one of the past threads but I am not able to get the result. I don't understand what the error message is reporting. Can someone help me? Many Thanks in advance.
C=['r.' 'g.' 'b.' 'c.'];
for ht = 0:(num-1)
for cmd = 1:4,
idx = (find(new_h == ht & new_cmd == cmd));
[r] = ind2sub(idx, [idx]);
chs = [new_cmd, new_c, new_s];
cmdgroup = chs([r],:);
c = cmdgroup(:,2);
s = cmdgroup(:,3);
cmd = cmdgroup(:,1);
plot(c, s, C(cmd));
axis ([-5000 40000 -100 900]);
hold on;
end;
end;
======================================================
Error message :
??? Error in color/linetype argument
On line 49 ==> plot(c, s, C(cmd));
I am having problem with using different colors base on the the various cmd in the for loop. I apply the suggested solution provided in one of the past threads but I am not able to get the result. I don't understand what the error message is reporting. Can someone help me? Many Thanks in advance.
C=['r.' 'g.' 'b.' 'c.'];
for ht = 0:(num-1)
for cmd = 1:4,
idx = (find(new_h == ht & new_cmd == cmd));
[r] = ind2sub(idx, [idx]);
chs = [new_cmd, new_c, new_s];
cmdgroup = chs([r],:);
c = cmdgroup(:,2);
s = cmdgroup(:,3);
cmd = cmdgroup(:,1);
plot(c, s, C(cmd));
axis ([-5000 40000 -100 900]);
hold on;
end;
end;
======================================================
Error message :
??? Error in color/linetype argument
On line 49 ==> plot(c, s, C(cmd));





RE: Problem with plotting with string of different color names
1) The loop index variable 'cmd' is altered inside the loop (line 10 of your code). Is this correct?
2) Matlab interprets
C=['r.' 'g.' 'b.' 'c.'];
as
C = ['r.g.b.c.'];
so C(1) is 'r', C(2) is '.', C(3) is 'g' etc.
One way around this is to replace
plot(c, s, C(cmd));
with
plot(c, s, C((cmd-1)*2+1:cmd*2));
A more rigorous way is to replace the string C with a cell array of strings and convert each element in the cell array to a string as required (using the 'char' command, ie:
C = {'r.' 'g.' 'b.' 'c.'};
(note the curly braces)
and then plot using
plot(c, s, char(C(cmd)));
Hope this helps
M
RE: Problem with plotting with string of different color names
Your suggested solution works.
Problem 1) is solved by changing to another name. typo error.
Problem 2) is solved by adapting to 2nd method.
Thank you very much. Have a Happy Christmas and Happy New Year 2003 to you & all forum users.