save a variable nameing it after a string

1 Ansicht (letzte 30 Tage)
Emil
Emil am 3 Feb. 2012
I have several matrices that I would like to save in a loop. I've tried to read all the save documents but it doesnt seam to work. I can save the matrix using a string and it becomes like A150.mat but I also want the matrix inside to be called that as well. The problem is that save() saves the matrix after what its called so when I get the name as a string(imported from a document outside matlab) its impossible to give the matrix that name. Thanks for any help

Akzeptierte Antwort

Kevin Holst
Kevin Holst am 3 Feb. 2012
can you not import the string prior to saving? something like:
...
str = importFun(file);
eval([str ' = matToSave;'])
save([str '.mat'],str)
eval(['clear ' str])
clear str
  3 Kommentare
Jan
Jan am 4 Feb. 2012
There can be more evil problems then "eval('clear all')":
str = 'x; system(''format C:'')'
eval(['clear ', str])
;-)
Emil
Emil am 6 Feb. 2012
Thank you, it worked perfectly! :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sean de Wolski
Sean de Wolski am 3 Feb. 2012
Either This or This

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by