Thread Subject: Extracting data from another M file

Subject: Extracting data from another M file

From: Wen Zhe

Date: 10 Mar, 2010 15:30:27

Message: 1 of 4

Hi guys (and gals),

Just a quick question, basically i have this M file that does some calculation and outputs value in a variable called u(t,r). Note the values are indexed.

Now, in a seperate M file, i want to call the previous M file to get values of u(t,r). How would i be able to do so?

Any help appreciated. Thanks!

Regards,

Wen Zhe

Subject: Extracting data from another M file

From: Wen Zhe

Date: 10 Mar, 2010 16:38:05

Message: 2 of 4

bump!

"Wen Zhe " <wenzhe2092@hotmail.com> wrote in message <hn8duj$d0q$1@fred.mathworks.com>...
> Hi guys (and gals),
>
> Just a quick question, basically i have this M file that does some calculation and outputs value in a variable called u(t,r). Note the values are indexed.
>
> Now, in a seperate M file, i want to call the previous M file to get values of u(t,r). How would i be able to do so?
>
> Any help appreciated. Thanks!
>
> Regards,
>
> Wen Zhe

Subject: Extracting data from another M file

From: Walter Roberson

Date: 10 Mar, 2010 17:36:27

Message: 3 of 4

Wen Zhe wrote:

> Just a quick question, basically i have this M file that does some
> calculation and outputs value in a variable called u(t,r). Note the
> values are indexed.

> Now, in a seperate M file, i want to call the previous M file to get
> values of u(t,r). How would i be able to do so?
> Any help appreciated. Thanks!

If the first m file is a script (no 'function' line in it) then in the
second m file just give the name of the first m file without the '.m'
extension and it will be run in the workspace appropriate for the second
file, leaving behind its variables.

If the first m file is a function, then it has its own workspace, and
variables in the workspace disappear after the function finishes
executing (except for 'global' and 'persistent' variables, and some
tricks involving passing the handles of subfunctions out of the
routine.) In this case, there is no way to access the variables after
the function has run, not without changes to the first m file to
deliberately make the variables available.

Subject: Extracting data from another M file

From: Wen Zhe

Date: 11 Mar, 2010 10:48:02

Message: 4 of 4

Thanks for the reply Walter.

So what are the tricks involved in getting the values in the variales from the first M file into the second M file?

Many thanks,

Wen Zhe

Walter Roberson <roberson@hushmail.com> wrote in message <hn8lat$22t$1@canopus.cc.umanitoba.ca>...
> Wen Zhe wrote:
>
> > Just a quick question, basically i have this M file that does some
> > calculation and outputs value in a variable called u(t,r). Note the
> > values are indexed.
>
> > Now, in a seperate M file, i want to call the previous M file to get
> > values of u(t,r). How would i be able to do so?
> > Any help appreciated. Thanks!
>
> If the first m file is a script (no 'function' line in it) then in the
> second m file just give the name of the first m file without the '.m'
> extension and it will be run in the workspace appropriate for the second
> file, leaving behind its variables.
>
> If the first m file is a function, then it has its own workspace, and
> variables in the workspace disappear after the function finishes
> executing (except for 'global' and 'persistent' variables, and some
> tricks involving passing the handles of subfunctions out of the
> routine.) In this case, there is no way to access the variables after
> the function has run, not without changes to the first m file to
> deliberately make the variables available.

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com