MATLAB: GUI: How to save figure properties to files

callbackfigureguisave

Hi all, I would like to save figure properties(legend,background colors…) to some kind of files, so that I can recall them later. I used guidata(hObject,handles) to pass the figure properties from one callback function to another: save_setup_Callback(hObject, eventdata, handles) Here's my code:
function save_setup_Callback(hObject, eventdata, handles)
configuration.x_axis=get(handles.x_axis,'String'); % save marked items in listboxes
configuration.y_axis=get(handles.y_axis,'String');
[FileName,FilePath]=uiputfile('configuration.mat','Save Configuration','Configuration');
if FileName == 0
msgbox('You have canceled saving the file (.mat)!','Warning: no files saved','warn');
else
file = strcat(FilePath,FileName);
save(file);
save(file,'-struct','handles2','legend','-append') % handles2 includes the figure properties
But then I got this error in command window when executing:
Error using save
The argument to -STRUCT must be the name of a scalar structure variable.
I personally think it's because legend is not a structure, but a ''1×1 Legend''. Also I'm not sure if ''Legend'' can be written into a .mat file. So how can I save such format to files? And in which format?
Thank you in advance 🙂

Best Answer

When you use -struct you can name only one variable, which will be broken up and its fields will become variables in the .mat file.