Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding legend to Matlab figure...

Status
Not open for further replies.

IceMan30

Military
Jan 19, 2011
32
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
lh=scribe.legend(ha,orient,location,position,children,listen,strings,propargs{:});

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!
 
Replies continue below

Recommended for you

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

:)
 
The gotcha with legends is that you have to have the same number of legend entries as curves, but I can't remember if that causes a fatal crash.

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor