how to name matfile from variable name

조회 수: 8 (최근 30일)
kev111
kev111 2016년 6월 9일
답변: Shameer Parmar 2016년 6월 10일
I am trying to allow end users to name the .mat file that will save current settings as a preset.
What have tried so far is:
presetName = inputdlg({'Enter a name for the Preset'},'Preset');
%presetNameMat = strcat( presetName,'.mat');
save('presetName');
SaveUserSettings(handles);
Which saves everything in a file called presetName.mat - and not a .mat file named from the variable presetName. If I try and pass the value instead I get : Error using save Argument must contain a string.

채택된 답변

Star Strider
Star Strider 2016년 6월 9일
This should work:
presetNameCell = inputdlg({'Enter a name for the Preset'},'Preset');
presetName = presetNameCell{:};
save(presetName);
You can of course combine them as:
save(presetNameCell{:});
I broke them out into separate lines so you can see how the code works.
  댓글 수: 2
kev111
kev111 2016년 6월 9일
Brilliant, many thanks.
Star Strider
Star Strider 2016년 6월 9일
My pleasure!

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

추가 답변 (1개)

Shameer Parmar
Shameer Parmar 2016년 6월 10일
Hi Kev111,
In your code, simply replace the line
save('presetName');
with
save(char(presetName));
and try..

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by