save

조회 수: 5 (최근 30일)
Hassan
Hassan 2011년 6월 9일
I have two variables:Var1=[1 2 3] and s='myData'. I am using assignin('base',s,Var1) to assign the contents of the text file as Var1 name. now I have another variable, myData=[1 2 3]. I wonder how I can save Var1 with the new name. Please let me know if I didn't ask it clearly.
Var1=[1 2 3]
s='myData'
assignin('base',s,Var1)
%now I have another variable, myData=[1 2 3] %now I want to save it with the new name with using the contents of s variable.
Save('C:\myData',assignin('base',s,Var1))

채택된 답변

Paulo Silva
Paulo Silva 2011년 6월 9일
save(['C:\' s],s) %save the mat file with the same name as the variable

추가 답변 (2개)

Krishna
Krishna 2011년 6월 9일
can you rephrase the question clearly please..
  댓글 수: 1
Hassan
Hassan 2011년 6월 9일
I edited the question, not sure if it's still clear.

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


Krishna
Krishna 2011년 6월 9일
Hi Hassan,
If you are trying to name your data you can do it using eval function as follows, FOR eg: T=[1;2;3;4;]; and you want to name this as 'testmatrix' then eval(strcat('testmatrix','= T;'));
you can do the same where T can be struct or a file etc.. Hope this helps.
  댓글 수: 2
Hassan
Hassan 2011년 6월 9일
thanks Krishna for the comment. I didnt know about eval() but it seems it does the same as assignin().
Paulo Silva
Paulo Silva 2011년 6월 9일
please read this http://www.mathworks.com/support/tech-notes/1100/1103.html

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by