Got Questions? Get Answers.
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:
variables in titles ??

Subject: variables in titles ??

From: Juliette Salexa

Date: 29 May, 2009 17:15:20

Message: 1 of 7

Let's set the variable number=5.

If I write underneath a plot command "title(number)"
The title ofmy plot is 5

Now what if I want to do something like "title('plot with frequency set to equal' number)"

The overall goal is to have the title being "Plot with frequency = number , and wavelength = number2 "

where number and number2 are predefined variables.

Any ideas ??

Subject: variables in titles ??

From: John

Date: 29 May, 2009 17:33:01

Message: 2 of 7

Use sprintf to format your title string -

str = sprintf('Plot with frequency = %f , and wavelength = %f',number,number2);
title(str);

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <gvp578$p93$1@fred.mathworks.com>...
> Let's set the variable number=5.
>
> If I write underneath a plot command "title(number)"
> The title ofmy plot is 5
>
> Now what if I want to do something like "title('plot with frequency set to equal' number)"
>
> The overall goal is to have the title being "Plot with frequency = number , and wavelength = number2 "
>
> where number and number2 are predefined variables.
>
> Any ideas ??

Subject: variables in titles ??

From: wthurt

Date: 29 May, 2009 17:32:45

Message: 3 of 7

How about something like

str=sprintf('Plot with frequency = %d and wavelength = %d', number1, number2);

title(str)



You then need to review the different ways to format the output, eg %d,%6.3f etc

Subject: variables in titles ??

From: Juliette Salexa

Date: 29 May, 2009 17:56:01

Message: 4 of 7

That works very well!

But I guess I can't incporporate latex into my title then ??

usually I do title('\frac{1}{2}','Interpreter','latex') and the fraction enters my title, but with this method it seems that the latex doesn't come out or I get an error message.

Subject: variables in titles ??

From: Bruno Luong

Date: 29 May, 2009 19:28:01

Message: 5 of 7

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <gvp7jh$2q0$1@fred.mathworks.com>...
> That works very well!
>
> But I guess I can't incporporate latex into my title then ??
>
> usually I do title('\frac{1}{2}','Interpreter','latex')

Use Math mode in laTex
> title('$\frac{1}{2}$','Interpreter','latex')

Bruno

Subject: variables in titles ??

From: aman

Date: 3 Aug, 2010 23:42:05

Message: 6 of 7

Thanks alot it was a great help, can we do something similar with save as command ...??
I am analyzing data for every month with multiple plots,so, every time I have to change month name in my save option before executing my code.So, is there any way I can set variable for that and just vary that.I will appreciate any kind of help.
Thanks in advance.
Aman

"John" <sjohn@cnbc.cmu.edu> wrote in message <gvp68d$3ng$1@fred.mathworks.com>...
> Use sprintf to format your title string -
>
> str = sprintf('Plot with frequency = %f , and wavelength = %f',number,number2);
> title(str);
>
> "Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <gvp578$p93$1@fred.mathworks.com>...
> > Let's set the variable number=5.
> >
> > If I write underneath a plot command "title(number)"
> > The title ofmy plot is 5
> >
> > Now what if I want to do something like "title('plot with frequency set to equal' number)"
> >
> > The overall goal is to have the title being "Plot with frequency = number , and wavelength = number2 "
> >
> > where number and number2 are predefined variables.
> >
> > Any ideas ??

Subject: variables in titles ??

From: Jan Simon

Date: 4 Aug, 2010 00:44:05

Message: 7 of 7

Dear Aman,

> Thanks alot it was a great help, can we do something similar with save as command ...??
> I am analyzing data for every month with multiple plots,so, every time I have to change month name in my save option before executing my code.So, is there any way I can set variable for that and just vary that.

Do you mean the SAVEAS command? Or with "save" as command?
What is "change month name in my save option"?

You can use SPRINTF to create a file name for the SAVE or SAVEAS commands.

Kind regards, Jan

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