Save imported vector array with matlab file for later use
1 次查看(过去 30 天)
显示 更早的评论
I have imported a text file, containing columns of numbers, as vectors.
However, when I save my matlab file, close and reopen, the data is gone. I have to reimport the data.
is there a way for the imported data/vectors in the workspace to be preserved.
0 个评论
采纳的回答
dpb
2024-9-6
移动:dpb
2024-9-6
When you close MATLAB itself??? No, when you close any application its working data are gone because the memory is released back to the system. MATLAB will reopen files in the editor, but it doesn't restore the whole working environment; if you want to do that routinely, you could save your workplace and then have a line in your startup.m file that reloads a given .mat file;, say "WORKSPACE".
I actually have a pair of routines that does that
% BACKUP_WORKSPACE
% Backup current workspace to "WORKING ddMMMyyyy hhmm.mat"
fn="WORKING-"+string(datetime(now,'ConvertFrom','datenum','Format','yyyy_MM_dd(MMM)_HHmm'));
if exist('comment','var')
fn=fn+"-"+string(comment);
end
clear d % don't save the dir() struct
save(fn)
clear comment % don't leave last comment hanging around -- may not like this
and
% LOADLAST.m
% load last WORKING backup file w/o needing date...
dd=dir('WORK*.mat');
[~,ix]=sort([dd.datenum],'descend');
dd=dd(ix);
load(dd(1).name)
disp(['Loaded: ' dd(1).name])
clear dd
These are scripts so they run in the workspace; the BACKUP routine will add as an addition to the file name the content of a variable comment; the LOADLAST routine looks for the latest of the set and loads it; one can get/load any specific one by manually loading the specific file.
Everything will be as you left it at the time you did the particular backup.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!