Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
plot legend with string and non-string value

Subject: plot legend with string and non-string value

From: edward kabanyas

Date: 23 Aug, 2012 01:18:07

Message: 1 of 3

Hi all,

I have a simple question about defining legend for my plot. For example, I plot simply my data as:

h = plot(x1, y1, 'o', x2, y2, '+')
legend([h(1) h(2) ], 'z1=a1x^b1', 'z2=a1x^b1');

Problem: values of a and b are obtained from another source/question and not inputted by our hand. For example, a and b are ineteger/float, how to call them into that legend ?

Thanks for share..

Edward

Subject: plot legend with string and non-string value

From: dpb

Date: 23 Aug, 2012 02:20:07

Message: 2 of 3

On 8/22/2012 8:18 PM, edward kabanyas wrote:
...

> h = plot(x1, y1, 'o', x2, y2, '+')
> legend([h(1) h(2) ], 'z1=a1x^b1', 'z2=a1x^b1');
>
> Problem: values of a and b are obtained from another source/question and
> not inputted by our hand. For example, a and b are ineteger/float, how
> to call them into that legend ?
...

 >> a=[1.44 12.1];b=[0.4 1.02];
 >> l=sprintf('z%d=%4.2fx^%5.2f\n',[[1:2]; a' b'])
l =
z1=1.44x^12.10
z2=0.40x^ 1.02

 >> legend(h),l);

--

Subject: plot legend with string and non-string value

From: dpb

Date: 23 Aug, 2012 12:47:01

Message: 3 of 3

On 8/22/2012 9:20 PM, dpb wrote:
...

> >> a=[1.44 12.1];b=[0.4 1.02];
> >> l=sprintf('z%d=%4.2fx^%5.2f\n',[[1:2]; a' b'])
...

Oops, the ";" was a typo I didn't notice, sorry...arrange in intended
order--

 >> [[1:2]' a' b']'
ans =
     1.0000 2.0000
     1.4400 12.1000
     0.4000 1.0200
 >> l=sprintf('z%d=%4.2fx^%4.2f\n',[[1:2]' a' b']')
l =
z1=1.44x^0.40
z2=12.10x^1.02

 >> legend(h,l);

--

Tags for this Thread

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.

Contact us