Effacer les filtres
Effacer les filtres

Save/load button in gui

3 vues (au cours des 30 derniers jours)
Gabri
Gabri le 8 Juin 2018
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Juin 2018
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

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by