help-octave
[Top][All Lists]
Advanced

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

Re: variable initialization


From: Colin Macdonald
Subject: Re: variable initialization
Date: Tue, 19 Jun 2018 10:15:37 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 2018-06-19 08:05 AM, Luca Salardi wrote:
i want to initialize a variable only the first time

i=0;  % i want initialize this variable only first time (i don't want to
assign value 0 in all cycles)

if (i>5) expression;


i=expression();

If this is inside a function, you can use a persistent variable.

persistent i

if (isempty(i))
  i = 0
end

...

cheers,
Colin



reply via email to

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