Save data before error
이전 댓글 표시
Hi. I have run a MATLAB code and at the last step it faced with error. Running process takes me time about 7 days, so, I want to save available data until this step to the file. I could not see any data in workspace. Please let me know how can I save these data. Cheers,
댓글 수: 1
Azzi Abdelmalek
2012년 11월 14일
What kind of data do you want to save
답변 (1개)
I recommend you either wrap all of your code in a TRY-CATCH or use DBSTOP so that you don't lose your data again. Note that if you use the TRY-CATCH approach, you should wrap the code itself, not wrap a function call! If the reason for this is not clear, play around with the idea before you use it on code that takes hours or days to run...
try
% Your code
catch
% Save everything in the WS to mycode_errored.mat
save mycode_errored
end
or
% This will stop in debug mode if an error occurs.
% so that you can examine all data, save whatever, etc.
dbstop if error
% Run your code here.
댓글 수: 3
Terje Nilsen
2019년 10월 7일
Well I have same issue, but do not always know exactly the code line it will stop, that is why I debug. Most tools thes days are able to freez everything when an error occure so we can analyze variable, parameters etc. why is this so hard in matlab? Seems like an obvious thing, have missed this for years.
Hung Dao
2021년 3월 3일
I am experiencing the same issue. it takes me days to run the code.
I upload my code and run it on a supercomputer so I cannot use the 'Pause on errors' function.
Is there anyway to save all the data, variables, workspace at the time where an error occur?
카테고리
도움말 센터 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!