필터 지우기
필터 지우기

how to save past outputs of a function

조회 수: 4 (최근 30일)
Dev
Dev 2015년 3월 9일
편집: Dev 2015년 3월 10일
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.

채택된 답변

dpb
dpb 2015년 3월 9일
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
Dev
Dev 2015년 3월 10일
Thank You very much. It worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by