Contact US

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!

*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

Adding legend to Matlab figure...

Adding legend to Matlab figure...

Adding legend to Matlab figure...

Really simple question...

What's the trick to adding a legend to a matlab plot? I'm  a pretty experienced Matlab user, just shaking the rust off after a couple years of little use. To cite the example in a Matlab manual (version 7, from early 2009 I think):

>> x = 0:pi/200:2*pi;
>> y = sin(x);
>> y2 = sin(x-.25);
>> y3 = sin(x-.5);
>> plot(x,y,x,y2,x,y3)
>> legend('sin(x)','sin(x-.25)','sin(x-.50)')

When I plot this, the figure comes up fine, but I get the following errors in regards to the legend:

??? Error using ==> hgconvertunits
Invalid object handle.

Error in ==> legend>make_legend at 386

Error in ==> legend at 285
        [h,msg] = make_legend(ha,varargin(arg:end));


I've yet to step through the "legend" code, but really, for a simple figure legend, this seems a bit ridiculous.

Any thoughts? What the crap am I doing wrong??

Thanks in advance!

RE: Adding legend to Matlab figure...

..Apparently I had some sort of Windoze memory error. Upon accidentally closing Matlab and restarting, "legend" seems to work fine.


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! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close