MATLAB: Save/load button in gui

guideloadsave

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?

Best Answer

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