Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • 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
Joined
Jan 19, 2011
Messages
32
Location
US
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!
 
..Apparently I had some sort of Windoze memory error. Upon accidentally closing Matlab and restarting, "legend" seems to work fine.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top