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:
Defining data table globally

Subject: Defining data table globally

From: Exergy

Date: 26 Nov, 2012 19:12:12

Message: 1 of 4

I wrote a code that has this line:

data = janload ('nasa.fit');

This "data" contains thermodynamics tables, and I used this "data" in subroutines of this code but I got the "Undefined function or variable 'data'." error when I use it in subroutines and since subroutines are used for iteration so if I add "data = janload ('nasa.fit');" in subroutines it keeps loading it in every iteration. How can I define "data" as global?

Subject: Defining data table globally

From: someone

Date: 26 Nov, 2012 19:29:15

Message: 2 of 4

"Exergy " <faraz.aria@gmail.com> wrote in message <k90euc$ck$1@newscl01ah.mathworks.com>...
> I wrote a code that has this line:
>
> data = janload ('nasa.fit');
>
> This "data" contains thermodynamics tables, and I used this "data" in subroutines of this code but I got the "Undefined function or variable 'data'." error when I use it in subroutines and since subroutines are used for iteration so if I add "data = janload ('nasa.fit');" in subroutines it keeps loading it in every iteration. How can I define "data" as global?

Simply add the statement:

global data

to each subroutinbe, function, workspace, etc.
that uses the variable data. See also:

doc global

Subject: Defining data table globally

From: dpb

Date: 26 Nov, 2012 19:32:46

Message: 3 of 4

On 11/26/2012 1:29 PM, someone wrote:
> "Exergy " <faraz.aria@gmail.com> wrote in message
> <k90euc$ck$1@newscl01ah.mathworks.com>...
>> I wrote a code that has this line:
>>
>> data = janload ('nasa.fit');
>>
>> This "data" contains thermodynamics tables, and I used this "data" in
>> subroutines of this code but I got the "Undefined function or variable
>> 'data'." error when I use it in subroutines and since subroutines are
>> used for iteration so if I add "data = janload ('nasa.fit');" in
>> subroutines it keeps loading it in every iteration. How can I define
>> "data" as global?
>
> Simply add the statement:
>
> global data
>
> to each subroutinbe, function, workspace, etc. that uses the variable
> data. See also:
>
> doc global

Or, instead of making it global and having the resultant difficulties
that can bring w/ code maintenance and reliability, simply add 'data' to
the argument list of functions requiring it and pass the array to them.
  No need to reread it every time.

I'd name it something more apropos than just 'data' reflecting what it
actually is as well...

--

Subject: Defining data table globally

From: Exergy

Date: 27 Nov, 2012 11:46:05

Message: 4 of 4

dpb <none@non.net> wrote in message <k90g6l$apn$1@speranza.aioe.org>...
> On 11/26/2012 1:29 PM, someone wrote:
> > "Exergy " <faraz.aria@gmail.com> wrote in message
> > <k90euc$ck$1@newscl01ah.mathworks.com>...
> >> I wrote a code that has this line:
> >>
> >> data = janload ('nasa.fit');
> >>
> >> This "data" contains thermodynamics tables, and I used this "data" in
> >> subroutines of this code but I got the "Undefined function or variable
> >> 'data'." error when I use it in subroutines and since subroutines are
> >> used for iteration so if I add "data = janload ('nasa.fit');" in
> >> subroutines it keeps loading it in every iteration. How can I define
> >> "data" as global?
> >
> > Simply add the statement:
> >
> > global data
> >
> > to each subroutinbe, function, workspace, etc. that uses the variable
> > data. See also:
> >
> > doc global
>
> Or, instead of making it global and having the resultant difficulties
> that can bring w/ code maintenance and reliability, simply add 'data' to
> the argument list of functions requiring it and pass the array to them.
> No need to reread it every time.
>
> I'd name it something more apropos than just 'data' reflecting what it
> actually is as well...
>
> --
Adding "data" to input variables worked.
Thanks

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