how to intialize a variable only once?the below written code should execute only once.later the value must b retained. how it is done
Mostra commenti meno recenti
example
persistent a
if isempty (a)
a=0;
end
2 Commenti
rashmi am
il 1 Mar 2015
Risposta accettata
Più risposte (1)
Walter Roberson
il 1 Mar 2015
0 voti
That code looks fine in itself. See here for the examples in the documentation for persistent. persistent variables, like global variables, are initialized to [], so testing them for that value, just as you did, is correct for determining whether they have been initialized.
Note that persistent variables are only visible inside the routine they are declared in, so they are not the correct choice for creating a shared variable.
1 Commento
rashmi am
il 1 Mar 2015
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!