Effacer les filtres
Effacer les filtres

how to save past outputs of a function

3 vues (au cours des 30 derniers jours)
Dev
Dev le 9 Mar 2015
Modifié(e) : Dev le 10 Mar 2015
I have the following code :
function NM
options = optimset('Display','iter','TolX',1e-10,'TolFun',1e-10);
[x,fval] = fminsearch(@(x)ban2(x),1,options);
function ban1 = ban2(x)
x1 = x
iono_layer_parms = [x(1), x(2), -1, -1, -1, -1];
[iono, iono_extra] = iri2012(lat, lon, x, UT,ht_start, ht_step,num_hts);
ionofreq = 0.008978663597663*sqrt((10.^(-6))*(iono(1,18:end)));
D6xb = interp1(alt3(101:697),D6xa(101:697),alt(26:175));
D6xc = 0.008978663597663*sqrt(D6xb);
ban = ionofreq(9:158) - D6xc;
ban1 = sum(ban.^2)
I want to save the variables x used in each iteration. I tried using persistent variables at the fourth line of the code but got error message :The PERSISTENT declaration must precede any use of the variable. x.
I also tried to use persistent variables at other places in function ban1 but got the same error message. Any help will be greatly appreciated.

Réponse acceptée

dpb
dpb le 9 Mar 2015
Use the output function option to write the function to return the values. There's an example in the documentation that creates a history as you're looking for...
In the local doc for R2012b here there's an example w/ a history specifically like you're asking; that doesn't seem to show up so easily anyway w/ the online doc's...not sure what's changed if anything besides the documentation.
  1 commentaire
Dev
Dev le 10 Mar 2015
Thank You very much. It worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by