필터 지우기
필터 지우기

Save and restore state for a deployed application

조회 수: 2 (최근 30일)
Kah Joon Yong
Kah Joon Yong 2015년 10월 21일
댓글: Kah Joon Yong 2015년 10월 21일
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?

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 10월 21일
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
Kah Joon Yong
Kah Joon Yong 2015년 10월 21일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by