how to name matfile from variable name

1 Ansicht (letzte 30 Tage)
kev111
kev111 am 9 Jun. 2016
Beantwortet: Shameer Parmar am 10 Jun. 2016
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.

Akzeptierte Antwort

Star Strider
Star Strider am 9 Jun. 2016
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 Kommentare
kev111
kev111 am 9 Jun. 2016
Brilliant, many thanks.
Star Strider
Star Strider am 9 Jun. 2016
My pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Environment and Settings 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