Hi, I have qestion about SAVE command behavior in GUI. In my GUI I use command:
save rotor_spec; %works fine...saves all variables to rotor_spec.mat
But today I tried make option for user to choose name for the file, not only rotor_spec.mat; I used this:
name = uiputfile('*.mat')
save name; % or save('name')
And it does not work. I do not realy need this for my GUI, but I would like to know, why it does not work.

 채택된 답변

John D'Errico
John D'Errico 2014년 12월 18일
편집: John D'Errico 2014년 12월 18일

2 개 추천

The one thing you did NOT try was
save(name)
name is a variable, that contains a file name. Use it as such.
When you do this:
save name
MATLAB does create a mat file. The name of that file will be name.mat. Look in your directory.
This happens because MATLAB functions can also be used as commands. When you do so, MATLAB actually passes the string 'name' to the save function, as if you had executed
save('name')
See that this is NOT the same as passing the contents of the VARIABLE name to save. When you use a function as a command, it takes whatever follows the command as literal text, a string, and passes that to your chosen function.

댓글 수: 1

Jiri Franc
Jiri Franc 2014년 12월 18일
Thank you for great explanation. I thought I tried this posibility too. Apparently, I should take a break. Thank you once more.

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

추가 답변 (1개)

Adam
Adam 2014년 12월 18일
편집: Adam 2014년 12월 18일

1 개 추천

Try:
save( name )
I think the
save name
without the parenthesis only works if name is an absolute string, not a variable e.g.
save 'MyFile.mat'
though I may be wrong.

댓글 수: 2

save name
DOES do something. It DOES work, just that it does something you may not expect. See my answer. This is due to having used the command form of save, as opposed to using the function form of save.
Jiri Franc
Jiri Franc 2014년 12월 18일
Thanks, you are right...it works.

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

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

태그

질문:

2014년 12월 18일

댓글:

2014년 12월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by