How do I save all of the workspace variables except for a certain specified variable name in MATLAB 7.12 (R2011a)?
230 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 18 Mär. 2013
Bearbeitet: MathWorks Support Team
am 12 Nov. 2013
I have a set of variables in the MATLAB base workspace and I would like to be able to save them. There is one variable in the workspace that causes the MAT file to be unloadable if it is saved. I would like a way of saving all of the variables in the workspace except for this specified variable.
Akzeptierte Antwort
MathWorks Support Team
am 18 Okt. 2013
To save all of the variables in the MATLAB workspace except for certain specified variable names, use a regular expression such as the following:
>> save test -regexp ^(?!(variableToExclude1|variableToExclude2)$).
or in the functional form
>> save(fname,'-regexp','^(?!(variableToExclude1|variableToExclude2)$). ')
Note that the period at the end of the regular expression is necessary. The following example demonstrates how this can be used to save all variables except for 'a' and 'd'.
>> clear;
>> a = 3; b = 4; c = 5; d = 6;
>> save test -regexp ^(?!(a|d)$).
>> clear;
>> load test;
Or in the functional form,
>> save('test', '-regexp', '^(?!(a|d)$).')
Additionally, if the name of the variable to exclude is available as a string, the following syntax can be used:
>> avoidVariable = 'a';
>> save('test', '-regexp', ['^(?!', avoidVariable,'$).'])
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!