Thread Subject: defining text strings for a legend

Subject: defining text strings for a legend

From: Scott Sather

Date: 23 Aug, 2007 18:18:04

Message: 1 of 4

In my plot I have N curves generated using N values of X. I
want my the strings in my legend to show the values of X,
i.e., X1, X1, ... XN. Is there an elegant way to do this? I
don't want to do the following:

legend(num2str(X(1)), num2str(X(2)), ...)

because I don't necessarily know what N will be in advance.

Subject: defining text strings for a legend

From: Rick Rosson

Date: 23 Aug, 2007 19:36:00

Message: 2 of 4

Hi Scott,

If 'X' is a column vector, you can use the following:

   legend(num2str(X));

Alternatively, if 'X' is a row vector, then try:

   legend(num2str(X.'));

I hope that helps.

Thanks.

Rick



"Scott Sather" <john.doe.nospam@mathworks.com> wrote in message
news:fakj0r$bem$1@fred.mathworks.com...
> In my plot I have N curves generated using N values of X. I
> want my the strings in my legend to show the values of X,
> i.e., X1, X1, ... XN. Is there an elegant way to do this? I
> don't want to do the following:
>
> legend(num2str(X(1)), num2str(X(2)), ...)
>
> because I don't necessarily know what N will be in advance.
>
>

Subject: defining text strings for a legend

From: Scott Sather

Date: 23 Aug, 2007 20:30:45

Message: 3 of 4

Thanks, Rick. The second method worked for me. I had tried
the first method eariler, but it just concatenated all the
vaules into a one long legend entry.

Scott

Subject: defining text strings for a legend

From: Miguel Torres

Date: 13 Feb, 2011 06:26:04

Message: 4 of 4

Dear Rick,

I would like to go one step further and do the following: I have 2 column vectors of different lengths, with data, in the same units but from 2 different samples. I want to make a plot and indicate in the legend the units and which sample they come from.

e.g.

v1=[1;2;3;4];
v2=[1;2;3];

How can I make the command legend generate on my plot, a legend like:

1 m, sample 1
2 m, sample 1
3 m, sample 1
4 m, sample 1
1 m, sample 2
2 m, sample 2
3 m, sample 2

I guess I have to use a combination of for loops and strcat, however I think you might know a more efficient way.

Regards,

Miguel.

"Rick Rosson" <rrosson@mathworks.com> wrote in message <faknj3$8aj$1@fred.mathworks.com>...
> Hi Scott,
>
> If 'X' is a column vector, you can use the following:
>
> legend(num2str(X));
>
> Alternatively, if 'X' is a row vector, then try:
>
> legend(num2str(X.'));
>
> I hope that helps.
>
> Thanks.
>
> Rick
>
>
>
> "Scott Sather" <john.doe.nospam@mathworks.com> wrote in message
> news:fakj0r$bem$1@fred.mathworks.com...
> > In my plot I have N curves generated using N values of X. I
> > want my the strings in my legend to show the values of X,
> > i.e., X1, X1, ... XN. Is there an elegant way to do this? I
> > don't want to do the following:
> >
> > legend(num2str(X(1)), num2str(X(2)), ...)
> >
> > because I don't necessarily know what N will be in advance.
> >
> >
>
>

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
legend Scott Sather 23 Aug, 2007 14:20:21
rssFeed for this Thread

Contact us at files@mathworks.com