Save and restore state for a deployed application
4 views (last 30 days)
Show older comments
Kah Joon Yong
on 21 Oct 2015
Commented: Kah Joon Yong
on 21 Oct 2015
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?
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!