How to save specific variable names
Show older comments
Hello!
I have a large workspace and i want to save workspace variables that includes specific characters and letters. For example i want to save multiple variables that contains "T22P50" in their name. For instance, I got the variable names "Pressure_T22P50", "Position_T22P50" etc and i want to save these into a .mat file. Since these variables changes for different tests (T22P50, T30P50 etc), is there a way that the save function can search in the workspace for variables containing the specific characters, instead of manually changing them each time?
I hope the question is clear, thanks in advance!
1 Comment
Note that your code would be much simpler, faster, and more reliable if you did not put meta-data into variable names:
Better code (simpler, faster, more reliable, easier to read,...) would simply use indexing or fieldnames instead of putting meta-data into variable names. Then your question would simply require saving one variable, and would not rely on ugly hack code.
Accepted Answer
More Answers (1)
Fangjun Jiang
on 27 Apr 2017
Vars=who('*_T22P50');
save('MatFile',Vars{:});
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!