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:
how use from legend in a for loop?

Subject: how use from legend in a for loop?

From: ghasem

Date: 24 May, 2013 07:47:08

Message: 1 of 2

Hi.
I want to use from legend in a for loop.
for example,my code is as following:

for f=[50e6 100e6 500e6 1e7]
... % a section from my code
plot(x,y) % y is updated in each for loop
hold all
end

I can plot my figures with different colors.in this step I don't have any problem.BUT I don't know how automatically call legend in/out of for loop.
I know that I can use from following method in this example:
legend('f=50e6' , 'f=100e6' , 'f=500e6' , 'f=1e7')
but when number of "f" is large in my code,I want to use from a automatic method.
how use from cell array for this purpose?
thanks

Subject: how use from legend in a for loop?

From: dpb

Date: 24 May, 2013 12:12:45

Message: 2 of 2

On 5/24/2013 2:47 AM, ghasem wrote:
> Hi.
> I want to use from legend in a for loop.
> for example,my code is as following:
>
> for f=[50e6 100e6 500e6 1e7]
> ... % a section from my code
> plot(x,y) % y is updated in each for loop
> hold all
> end
>
> I can plot my figures with different colors.in this step I don't have
> any problem.BUT I don't know how automatically call legend in/out of for
> loop.
> I know that I can use from following method in this example:
> legend('f=50e6' , 'f=100e6' , 'f=500e6' , 'f=1e7')
> but when number of "f" is large in my code,I want to use from a
> automatic method.
> how use from cell array for this purpose?
> thanks

Convert the number to character representation for legend()

doc num2str
doc sprintf

--

Tags for this Thread

No tags are associated with 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