3

I have written a Matlab guide tool. But I need to give a lot of paths every time I start up the tool. Eg

/path/to/image/folder
/path/to/annotation/folder
/path/to/filelist1
/path/to/filelist2

Right now I have to click all buttons and search for the files manually using uigetfile which is tedious. Is there a way such that when I close Matlab guide it saves the last state and opens it again the next time that I use it?

mcExchange
  • 6,154
  • 12
  • 57
  • 103
  • You would need to do this by saving the data yourself somewhere on the file system and then loading it when you load the GUI. – Suever Aug 24 '16 at 14:02
  • Of course one method is to manually choose and save all you need and load the saved data in `OpeningFcn`. But I prefer to wait for a better solution. – Erfan Aug 24 '16 at 14:04
  • Hmm yeah I guess then the question is rather whether there is a `DeleteFcn` which is executed when closing the guide window – mcExchange Aug 24 '16 at 14:07
  • lucky you, there is a `DeleteFcn`: The `CloseRequestFcn` from your main figure – Finn Aug 24 '16 at 14:58

1 Answers1

1

Saving the previous GUI session is simple: use hgsave('filename').
See http://www.mathworks.com/help/matlab/ref/hgsave.html

Example:
1. In the CloseRequestFcn callback function, I added hgsave:

% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: delete(hObject) closes the figure
hgsave('test1.fig')

delete(hObject);
  1. I opened untitled1.fig:
    enter image description here

  2. Modified few GUI controls (include the text edit), and close the GUI.

  3. Open test1.fig, and get the last session:
    enter image description here

Rotem
  • 30,366
  • 4
  • 32
  • 65
  • Very good. It works. This link shows how to add the closeRequestFcn Callback: http://stackoverflow.com/questions/3000564/function-that-executes-on-gui-closing-in-matlab – mcExchange Aug 26 '16 at 07:46