Save and restore state for a deployed application

6 views (last 30 days)
I am using this method : http://blogs.mathworks.com/videos/2010/12/10/how-to-save-and-restore-state-of-a-gui-in-matlab/ to save and restore the last state of my gui.
Specifically everytime the gui close it saves a .mat file and when it opens the next time it loads the .mat file. However when I deploy the GUI into a standalone application, there is an error. I can't even close my application.
This is my save state Function:
function saveState(handles,fileName)
state.Items_Detail = get(handles.Items_Detail, 'Data');
state.Recipt_Num_val = get(handles.Recipt_Num_val, 'string');
if exist(fileName,'file')
fileNamewithPath=which(fileName);
save(fileNamewithPath,'state')
else
save(fileName,'state')
end
and my Loadstate Function:
function loadState(hObject,handles,fileName)
if exist(fileName,'file')
load(fileName)
set(handles.Items_Detail, 'Data' ,state.Items_Detail);
set(handles.Recipt_Num_val, 'string' ,state.Recipt_Num_val);
guidata(hObject,myhandles)
delete(fileName)
else
return;
end
Is there just solely because of the path problem or the deployed app can't write and modify a .mat file? Can anyone gives me a suggestion what I could do?

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 21 Oct 2015
Hi,
your app can load and save data when deployed. It's only that there is no current folder, or the current folder may be somewhere where you don't expect it to be.
My suggestion:
print in your load and save function the folder name, e.g.
function saveState(handles,fileName)
fileName
state.Items_Detail = get(handles.Items_Detail, 'Data');
and start your program not from windows explorer but out of a CMD window (Windows Start, type CMD, navigate to the folder where the exe is and start it). This way you'll see the folder names and error messages.
Titus
  1 Comment
Kah Joon Yong
Kah Joon Yong on 21 Oct 2015
Thx for the answer. That means I must include some paths in my GUI.
I have read some articles about path management for instance the one from Lauren: http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/
He suggested the use of functions like ctproot, addpath, path etc. But I am not sure when to include those.
Specifically I would like to install a new folder into the Program folder in C:// where the exe file is and save and load the .mat file to and from there everytime. How can I include that folder?

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!