フィルターのクリア

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 Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by