Parameters in GUI functions

Hi, I have this function to be used with GUI. But how do I pass over "parameter" to be used in another function (e.g RunButton_Callback)? If it is a text like in this example I found a workaround by set it to a textbox and then (in the other function) get it from that textbox. But what to do if it is a vector parameter?
function InputButton_Callback(hObject, eventdata, handle)
[Qfile]=uigetfile('*.txt','Select a file');
[parameter]=QImport(Qfile);

Respuestas (1)

Geoff Hayes
Geoff Hayes el 10 de Mzo. de 2016

0 votos

nilsotto - just save the parameter to the handles structure using guidata as
function InputButton_Callback(hObject, eventdata, handle)
[Qfile]=uigetfile('*.txt','Select a file');
[parameter]=QImport(Qfile);
% save as a field within parameter
handles.parameter = parameter;
% update the structure
guidata(hObject, handles);
Now, in any other callback you can check to see if this field exists and then use it.
function someOther_Callback(hObject, eventdata, handle)
if isfield(handles, 'parameter')
% do something with handles.parameter
end

1 comentario

nilsotto
nilsotto el 11 de Mzo. de 2016
Many thanks Geoff, now it works fine :-)

La pregunta está cerrada.

Productos

Etiquetas

Preguntada:

el 10 de Mzo. de 2016

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by