How do one save the output of matlab script when it runs for many days?

8 ビュー (過去 30 日間)
P K
P K 2019 年 1 月 31 日
コメント済み: Muhamed Eliyas 2020 年 10 月 6 日
Hello all---
I have a matlab script that run for 6-7 days. But, to be on safer side i want to save the output of the script at regular interval.This is to avoid the chances of loosing the data in case of unexpected termination. Is there a way to do this ?
In the script, there are loops inside a function.
Thanks in advance !

回答 (2 件)

KSSV
KSSV 2019 年 1 月 31 日
YOu can save the data into a mat file....check the following example:
filename='test.mat';
m = matfile(filename, 'Writable', true); %Note: writable is true by default IF the file does not exist
for i = 1:10
x = randn(1,100);
out = x.^2; %whatever you put into out is overwritten here anyway
m.out(i, 1:100) = out;
end
clear m;
  2 件のコメント
P K
P K 2019 年 2 月 6 日
Thanks for reply KSSV. Can you please check the Comment I have written in Walters reply? I think I didn't ask my question clearly.
Muhamed Eliyas
Muhamed Eliyas 2020 年 10 月 6 日
Display the current state of your knowledge • Calculate currentKnowledge using the same relationship as before, and the t we just calculated: k= −1 e−t/τ • Display the following text: At this time, I know X% of MATLAB
Please answer me with output

サインインしてコメントする。


Walter Roberson
Walter Roberson 2019 年 1 月 31 日
If you are talking about output to the command window, then you can use diary
Otherwise there is pretty much only save . You could consider having a timer object save the current content of variables that are in the base workspace.
  2 件のコメント
P K
P K 2019 年 2 月 6 日
@walter thanks for your response. Sorry for delay in replying.
Actually,I have a function. The function contains loop inside it.I can obtain the output of the function but i want to save the values at each iterations. This would avoid to run the whole loop again, if the code stops unexpectedly
%% This is just an example
function dy = fun(t,y)
N = numel(y)-1;
Pn = y(1:N);
P = y(N+1);
dPn = zeros(N,1);
for n = 2:N
summe = 0.0;
for r = 1:n-1
summe = summe+Pn(r)*Pn(n-r)
end
dPn(n) = -2*kp*Pn(n)*P + 0.5*2.0*kp*summe;
end
dP = ?
dPn(1) = ?
dy = [dPn;dP]
end
%% Can I save the output for each n,r so that I don't run the code again if it stops unexpectedly.
Thanks!
Walter Roberson
Walter Roberson 2019 年 2 月 6 日
You can call save() yourself, or you can use KSSV's idea of using matfile which will automatically write into the file, even extending variables, which might be more efficient.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by