フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Store permanently data taken from an edit text box of GUI

1 回表示 (過去 30 日間)
ericson
ericson 2014 年 2 月 7 日
閉鎖済み: Stephen23 2019 年 10 月 21 日
Hi! Is it possible to store/save the data taken from an edit text box permanently? (the data is still present even if I closed my program/GUI)

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 2 月 7 日
Absolutely. E.g., save your data as a .mat file. Check out this answer for more detail.
  2 件のコメント
ericson
ericson 2014 年 2 月 7 日
can you explain to me this part, I can't understand how it works
temp = load('testmatfile.mat');
data=temp.data;
uictagnames = fieldnames(data);
for i =1:numel(uictagnames)
str=sprintf('uicparams = fieldnames(data.%s)',uictagnames{i});
evalc(str);
for j = 1:numel(uicparams)
evalstr = sprintf('tempval = data.%s.%s',uictagnames{i},uicparams{j});
evalc(evalstr);
if ~isnumeric(tempval)
evalstr = sprintf('set(handles.%s,''%s'',''%s'')',uictagnames{i}, uicparams{j},tempval);
else
evalstr = sprintf('set(handles.%s,''%s'',%d)',uictagnames{i}, uicparams{j}, tempval);
end
evalc(evalstr);
end
end
Mischa Kim
Mischa Kim 2014 年 2 月 7 日
To see how it works, download reloading_param.m and the corresponding .fig file, remove some of the semi-colons from the evalstr commands in the code you pasted above and run the .m file.
Now, in the GUI enter a string in the top edit box, e.g., 007. When you do that the string gets saved in the variable handles.mystructdata in the callback function edit1_Callback. Hitting the SAVE DATA button saves the variable in data and to a .mat file:
data = handles.mystructdata
save('testmatfile.mat','data');
Close and re-open the GUI and hit the RELOAD DATA button.
temp = load('testmatfile.mat');
data=temp.data;
All the data from the .mat file is transfered into data. In the following loop the individual variables are backed out, one by one, and entered back into the corresponding GUI objects (which are recognized by their unique tags), the edit boxes, via the evalstr commands.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by