how to save past outputs of a function
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!