MATLAB: How to name matfile from variable name

guisave

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.

Best Answer

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.