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

조회 수: 6 (최근 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 CenterFile Exchange에서 Variables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by