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

28 views (last 30 days)
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 !

Answers (2)

KSSV
KSSV on 31 Jan 2019
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 Comments
P K
P K on 6 Feb 2019
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 on 6 Oct 2020
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

Sign in to comment.


Walter Roberson
Walter Roberson on 31 Jan 2019
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 Comments
P K
P K on 6 Feb 2019
@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 on 6 Feb 2019
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.

Sign in to comment.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!