Save imported vector array with matlab file for later use

1 回表示 (過去 30 日間)
Bill White
Bill White 2024 年 9 月 6 日
移動済み: dpb 2024 年 9 月 6 日
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.

採用された回答

dpb
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 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by