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:
passing string

Subject: passing string

From: sk maidul haque

Date: 28 Dec, 2010 12:41:05

Message: 1 of 3

I have a matlab program, where the command plot hasbeen used to get a plot of some curve. I want to pass the xlabel through the input of the program.
     I have tried to do it . Although, the string is coming, xlabel is not accepting the string. I am giving the following example to elucidate my problem.

function []=test(b)
c=cellstr(b);
f=c{1}
xlabel('f')

If this program is called by test('wavelength'), although f=wavelength answer comes, still xlabel of the obtained plot is f. I want the xlabel of the obtained plot should be wavelength instead of being f. Please help me to get rid of this problem.
Thank you in advance.

Subject: passing string

From: Oleg Komarov

Date: 28 Dec, 2010 12:55:06

Message: 2 of 3

"sk maidul haque" <skmaidulhaque@gmail.com> wrote in message <ifclt0$rig$1@fred.mathworks.com>...
> I have a matlab program, where the command plot hasbeen used to get a plot of some curve. I want to pass the xlabel through the input of the program.
> I have tried to do it . Although, the string is coming, xlabel is not accepting the string. I am giving the following example to elucidate my problem.
>
> function []=test(b)
> c=cellstr(b);
> f=c{1}
> xlabel('f')
>
> If this program is called by test('wavelength'), although f=wavelength answer comes, still xlabel of the obtained plot is f. I want the xlabel of the obtained plot should be wavelength instead of being f. Please help me to get rid of this problem.
> Thank you in advance.

xlabel('f')
you're passing the string 'f' when you want to pass the content of the variable f:
xlabel(f)

Oleg

Subject: passing string

From: Nasser M. Abbasi

Date: 28 Dec, 2010 12:57:18

Message: 3 of 3

On 12/28/2010 4:41 AM, sk maidul haque wrote:


> function []=test(b)
> c=cellstr(b);
> f=c{1}
> xlabel('f')
>
> If this program is called by test('wavelength'), although f=wavelength answer comes,
> still xlabel of the obtained plot is f. I want the xlabel of the obtained plot
> should be wavelength instead of being f. Please help me to get rid of this problem.
> Thank you in advance.

I have no idea why you are doing all the cell stuff.

why not just write

---------------
function foo (label)

plot(1:10); %or whatever your plot is
xlabel(label);

end
--------------------

call it as foo('wavelength')

?

--Nasser

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