save a variable nameing it after a string

조회 수: 1 (최근 30일)
Emil
Emil 2012년 2월 3일
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

채택된 답변

Kevin Holst
Kevin Holst 2012년 2월 3일
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
Jan
Jan 2012년 2월 4일
There can be more evil problems then "eval('clear all')":
str = 'x; system(''format C:'')'
eval(['clear ', str])
;-)
Emil
Emil 2012년 2월 6일
Thank you, it worked perfectly! :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2012년 2월 3일
Either This or This

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by