Filter löschen
Filter löschen

Save/load button in gui

3 Ansichten (letzte 30 Tage)
Gabri
Gabri am 8 Jun. 2018
Beantwortet: Walter Roberson am 8 Jun. 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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Jun. 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

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by