필터 지우기
필터 지우기

How to save results

조회 수: 2 (최근 30일)
Meriem Ben Kalia
Meriem Ben Kalia 2020년 8월 19일
댓글: Meriem Ben Kalia 2020년 8월 22일
Hello everyone,
I have a very long Code that need much time to simulate, I want to the save all variables (it didn't finish the simulation) and I want to resimulate with the same variables saved to obtain the result of the code .
N.B: I create 3 functions and main in my code

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 20일
편집: Walter Roberson 2020년 8월 20일
One technique to do this is to convert your for loops into while loops, like this:
if exist('recover.mat')
load('recover.mat');
else
I = 1;
J = 1;
K = 1;
end
while I <= max_I
while J <= max_J
while K =< max_K
do something
K = K + 1;
save recovery.mat
end
K = 1;
J = J + 1;
end
J = 1;
I = I + 1;
end
%when you get here you are done, so no need to set I=1
That is, instead of initializing the loop variables to 1 immediately like you would with
for I = 1 : max_I
for J = 1 : max_J
end
end
you continue on from whatever current values of I, J, K are active, and you do not reset those values until the end of the corresponding loop when you are setting up conditions for the next iteration of the enclosing loop.
If there is a failure, then the code should effectively end up restarting the computation from the beginning of the innermost loop iteration whose results were not already saved.
If some of the loops are short and fast you might not want to bother saving in the innermost, as saving takes time. You might, for example, want to move the save to after the J = J + 1, if the K loop is fast enough.
  댓글 수: 1
Meriem Ben Kalia
Meriem Ben Kalia 2020년 8월 22일
thank you

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by