Hello,
Don't you know, is there an easy to save all the variables except some from the environment into .mat file? It looks like it should be a standard option of the save command, but I can't figure how to implement it (with regexp, perhaps..).
I'm trying to save an environment consisting of many variables with a few of them being very large, but not needed to be saved.
Thank you,
M
|
|
0
|
|
|
|
Reply
|
Max
|
10/10/2010 7:39:04 PM |
|
How about you save out the ones you don't want to be saved in your main .mat file to another .mat file? Then clear those variables. Then save the entire workspace with all the variables that you *do* want into your main .mat file. Then reload the other mat files to restore those variables that you didn't want to save and delete their temporary mat file. Not sure it would save any time, but it would give you your mat file without the undesired variables in it.
|
|
0
|
|
|
|
Reply
|
Image
|
10/10/2010 8:06:04 PM
|
|
It surely would work. But it's slow and I'm trying to do as few as possible saving operations with Gb size data. Plus, HD space is also a consideration.
What I'm doing right now is using a custom code, where I find all the current variables with the 'who' command, then sift it, throwing out the variables which are not desired in the output and, finally, form a command string for saving, containing only the desired variables which I subsequently execute with eval. It works, I just thought there gotta be an easier solution (or maybe the same, but built-in)! And if there is none, it would be great to add this option into the standard 'save'!
Thanks.
"Image Analyst" <imageanalyst@mailinator.com> wrote in message <i8t6bb$7ig$1@fred.mathworks.com>...
> How about you save out the ones you don't want to be saved in your main .mat file to another .mat file? Then clear those variables. Then save the entire workspace with all the variables that you *do* want into your main .mat file. Then reload the other mat files to restore those variables that you didn't want to save and delete their temporary mat file. Not sure it would save any time, but it would give you your mat file without the undesired variables in it.
|
|
0
|
|
|
|
Reply
|
Max
|
10/10/2010 8:26:03 PM
|
|
It surely would work. But it's slow and I'm trying to do as few as possible saving operations with Gb size data. Plus, HD space is also a consideration.
What I'm doing right now is using a custom code, where I find all the current variables with the 'who' command, then sift it, throwing out the variables which are not desired in the output and, finally, form a command string for saving, containing only the desired variables which I subsequently execute with eval. It works, I just thought there gotta be an easier solution (or maybe the same, but built-in)! And if there is none, it would be great to add this option into the standard 'save'!
Thanks.
"Image Analyst" <imageanalyst@mailinator.com> wrote in message <i8t6bb$7ig$1@fred.mathworks.com>...
> How about you save out the ones you don't want to be saved in your main .mat file to another .mat file? Then clear those variables. Then save the entire workspace with all the variables that you *do* want into your main .mat file. Then reload the other mat files to restore those variables that you didn't want to save and delete their temporary mat file. Not sure it would save any time, but it would give you your mat file without the undesired variables in it.
|
|
0
|
|
|
|
Reply
|
Max
|
10/10/2010 8:27:03 PM
|
|
"Max " <nikitchmPublic@gmail.com> wrote in message
news:i8t7in$mk5$1@fred.mathworks.com...
> It surely would work. But it's slow and I'm trying to do as few as
> possible saving operations with Gb size data. Plus, HD space is also a
> consideration.
>
> What I'm doing right now is using a custom code, where I find all the
> current variables with the 'who' command, then sift it, throwing out the
> variables which are not desired in the output and, finally, form a command
> string for saving, containing only the desired variables which I
> subsequently execute with eval.
Do NOT use EVAL; you could use the functional form of SAVE and/or use
the -regexp flag.
http://www.mathworks.com/help/techdoc/ref/save.html?BB=1
listOfVariables = {'foo', 'x', 'y2'};
% do NOT use:
% s = 'save myfile.mat foo x y2';
% eval(s)
% instead use
save('myfile.mat', listOfVariables{:});
See the last example on that page for an example using the -regexp flag.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
|
|
0
|
|
|
|
Reply
|
slord (13267)
|
10/11/2010 3:37:01 AM
|
|
Steve, thanks a bunch. "save('myfile.mat', listOfVariables{:});" is what I was looking for.
I still exclude the names of the to-be-ignored-variables by going through a loop and checking whether they coincide with the variables in the "who" list. It certainly would be nicer to be able to use regular expression to say: "include all, except.." (excepting full names, but patterns), but I can't find a way to do it. Is it possible?
Thanks,
M
|
|
0
|
|
|
|
Reply
|
Max
|
10/11/2010 8:20:04 AM
|
|
|
5 Replies
486 Views
(page loaded in 0.054 seconds)
|