save variables in .mat files with desired name.
Mostra commenti meno recenti
I have a function where I do my calculation to get A cell or array. Now I want to save this array in a .mat file but I want to change the variable name.
myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation
save Data.mat myData
This saves my data in Data.mat file but with variable name myData. Now I want to save values of myData in .mat file but I want to save the value under a variable name given via input function. Something like:
myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation
newName = input('I want to save the variable under the name:', 's');
save Data.mat ???
I hope that make sense
Thanks
Risposta accettata
Più risposte (2)
Bruno
il 25 Lug 2019
Maybe, a simples way to answer that need is to do the following:
fname = sprintf('Data.mat', myData);
save(fname)
Hope it can help others.
1 Commento
Eleanna Kritikaki
il 28 Gen 2020
Damn right it did. Thanks man
Azzi Abdelmalek
il 11 Ago 2013
myData = [1 2 3 4 5 6 7 9];
newName = input('I want to save the variable under the name:', 's');
assignin('base',newName,myData)
save('Data.mat',newName)
3 Commenti
Sunil Shahi
il 12 Ago 2013
Jan
il 12 Ago 2013
Avoid to create variables dynamically by assignin or eval. There is always a better solution.
Azzi Abdelmalek
il 12 Ago 2013
myData = [1 2 3 4 5 6 7 8 9]; %data from my calculation
newName = input('I want to save the variable under the name:', 's');
a.(newName)=myData;
save('Data.mat','-struct','a',newName)
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!