Thread Subject: No way to parameterize a Matlab script?

Subject: No way to parameterize a Matlab script?

From: Dimitri Shvorob

Date: 28 Apr, 2008 10:30:05

Message: 1 of 8

By 'script', I mean an m-file run from Windows with

> matlab -automation -r mymfile

The issue is that I would like to pass a parameter to
mymfile - which is then more appropriately called
function - but the syntax above apparently doesn't let me
to.

Can anyone offer advice?

Thanks!

Subject: No way to parameterize a Matlab script?

From: Shaun

Date: 28 Apr, 2008 12:08:01

Message: 2 of 8

http://www.mathworks.com/support/solutions/data/1-16B8X.html

Subject: No way to parameterize a Matlab script?

From: Jos

Date: 28 Apr, 2008 12:12:01

Message: 3 of 8

"Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote in
message <fv48vd$ag4$1@fred.mathworks.com>...
> By 'script', I mean an m-file run from Windows with
>
> > matlab -automation -r mymfile
>
> The issue is that I would like to pass a parameter to
> mymfile - which is then more appropriately called
> function - but the syntax above apparently doesn't let me
> to.
>
> Can anyone offer advice?
>
> Thanks!

Assuming you need a parameter A in your script MyScript.m,
you can use

matlab -r "A=3;MyScript"

hth
Jos


Subject: No way to parameterize a Matlab script?

From: Jos

Date: 28 Apr, 2008 12:19:02

Message: 4 of 8

"Jos " <DELjos@jasenDEL.nl> wrote in message <fv4euh$9e4
$1@fred.mathworks.com>...
> "Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote
in
> message <fv48vd$ag4$1@fred.mathworks.com>...
> > By 'script', I mean an m-file run from Windows with
> >
> > > matlab -automation -r mymfile
> >
> > The issue is that I would like to pass a parameter to
> > mymfile - which is then more appropriately called
> > function - but the syntax above apparently doesn't let
me
> > to.
> >
> > Can anyone offer advice?
> >
> > Thanks!
>
> Assuming you need a parameter A in your script
MyScript.m,
> you can use
>
> matlab -r "A=3;MyScript"
>
> hth
> Jos
>
>


or make MyScript a function accepting a parameter and call
it like

matlab -r MyScript(3)

hth
Jos

Subject: No way to parameterize a Matlab script?

From: Dimitri Shvorob

Date: 28 Apr, 2008 14:33:02

Message: 5 of 8

> matlab -r test2(3)

The system could not find the environment option that was
entered.
test2(3) was unexpected at this time.



Subject: No way to parameterize a Matlab script?

From: Dimitri Shvorob

Date: 28 Apr, 2008 14:35:03

Message: 6 of 8

Oh, it should be *quoted*! Thanks a lot!

Subject: No way to parameterize a Matlab script?

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 28 Apr, 2008 14:37:40

Message: 7 of 8

In article <fv4n6u$33o$1@fred.mathworks.com>,
Dimitri Shvorob <not.dimitri.shvorob@gmail.com> wrote:
>> matlab -r test2(3)

>The system could not find the environment option that was
>entered.
>test2(3) was unexpected at this time.

Try quoting the argument. I don't recognize any shell that would
give the message you got, so I don't know what system you are using.

Unix systems:

matlab -r 'test2(3)'

Windows:

matlab -r "test2(3)"


If I understand correctly, you have to use the double-quotes in Windows.

In Unix you could use either single or double quotes. Using double quotes
will give you problems if you have any $ in your argument. Using
single quotes will give you problems if you have any single-quotes
in your argument.
--
  "I feel sorry for the person who can't get genuinely excited
  about his work. Not only will he never be satisfied, but he will
  never achieve anything worthwhile." -- Walter Chrysler

Subject: No way to parameterize a Matlab script?

From: Dimitri Shvorob

Date: 28 Apr, 2008 14:44:02

Message: 8 of 8

I have Windows XP.

matlab -r "test2('hello world')"

works fine.

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
script batch Dimitri Shvorob 28 Apr, 2008 06:30:07
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com