help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use existing variable


From: CdeMills
Subject: Re: How to use existing variable
Date: Mon, 8 Nov 2010 01:22:13 -0800 (PST)


Neil Ghosh wrote:
> 
> Hi,
> 
> I have a variable X=csvread('XXXX'); with huge data in it.
> 
> My function is written in a .m file  "MyPrg.m" and it uses the data in X
> and
> have reference to that variable.
> 
> Whenever I call MyPrg in command line it give me error 'X' is undefined ,
> however I dont have "clear" in my function
> It should recognize the global variable X.
> 
> I can not afford to read that huge file everytime in my function code.
> 

As others told, the problem description is a bit vague.
If you want to transmit data between the main environment (the command line)
and a function, you have a number of options:
1) have the function returns the data:
function resu = MyPrg(filename)
resu = csvread(filename)
endfunction
2) define some global var AT EACH LEVEL where you want to use it:
global X;
function status = MyPrg(filename)
global X;
X= csvread(filename)
status = true;
endfunction

Regards

Pascal
-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/How-to-use-existing-variable-tp3027599p3031664.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]