Save/load button in gui

3 次查看(过去 30 天)
I'm developing a GUIDE tool and I would like to add a button to save the parameters that in my opinion are correct, that are inside various textbox. Then another button to load the saved file in the corresponding text box. The saved file could be of any type: txt, excel or whatever
Is it possible?

采纳的回答

Walter Roberson
Walter Roberson 2018-6-8
Sure
function save_params_Callback(hObject, event, handles)
names_to_save = {'editbox1', 'editbox2', 'velocity'};
num_to_save = length(names_to_save);
data_to_save = cell(num_to_save, 2);
for K = 1 : num_to_save
thisname = names_to_save{K};
thisvalue = get(handles.(thisname), 'String');
data_to_save{K,1} = thisname;
data_to_save{K,2} = thisvalue;
end
save('saved_params.mat', 'data_to_save');
To load:
function load_params_Callback(hObject, event, handles)
datastruct = load('saved_params.mat', 'data_to_save');
data_to_save = datastruct.data_to_save;
for K = 1 : size(data_to_save,1)
thisname = data_to_save{K,1};
thisvalue = data_to_save[K,2};
if isfield(handles.(thisname)) && isa(handles.(thisname), 'uicontrol')
set(handles.(thisname), 'String', thisvalue);
end
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by