How to save workspace in stages while optimizing disk space
3 ビュー (過去 30 日間)
I have a task that is divided into 2 stages for each I have developed a script, say script A and B.
After satisfactory result from A, I have saved the workspace in a mat file say 'A.mat'.
For next stage, everytime I load A.mat and proceed with the script B which depends on variables from script A. The final result are saved in say 'B.mat'
Now for my analysis, I change some parameter and run script B multiple times and save result to 'B1.mat', 'B2.mat', 'B3.mat', etc.
THE ISSUE: With every save 'B*.mat', variables of 'A.mat' are simply getting repeated. This consumes unnecessary space.
I WISH: To save all variables to 'B*.mat' file with exception of variables stored in 'A.mat'
% load variable list from 'fileA.mat'
% load current variables list
% compare two list and save only newly created variables to 'fileB.mat'
I could do this with fetching strings corresponding to variable names... basically a tedius file handling code, but really wish for a simpler matlab syntax as alternative.
回答 (2 件)
Steven Lord 2022 年 9 月 29 日
How are you loading your data? Are you calling load with an output argument or without?
If you called load with an output argument all the variables from A.mat will be fields of one struct array in the workspace. You could clear that variable before saving or use the -regexp option to exclude that struct array.
Another alternative would be to pack the variables you've created in the function into a struct array and use the -struct option to save the fields of that struct as independent variables in the B.mat file.