×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Problem with plotting with string of different color names

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));

RE: Problem with plotting with string of different color names

I see a combination of two problems causing this error

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

(OP)
Hi MikeP,

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources