フィルターのクリア

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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by