How to pass parameters between callback (GUI) in different buttongroup
Mostrar comentarios más antiguos
I'am writting a program with different callback function and i use
setappdata(hObject.Parent,'START',0)
getappdata(hObject.Parent,'START');
for exchange parameters that are define in fig that include all gui object. When i do this with callback from gui object in the same uibuttongroup, it work well, but if the gui object are in two different uibuttongroup it doesn't work. And i don't know why!!! Please help me!!
1 comentario
Respuestas (3)
Adam
el 8 de Feb. de 2017
1 voto
The reason why ought to be quite simple as you basically said it yourself, you just maybe didn't realise.
The buttons are in different uibuttongroups, i.e. they have a different parent, i.e. hObject.Parent is not the same for both so you saved your 'START' to one place and try to get it from another.
If you want to share information across groups then save it to somewhere higher up that is common to both or give a more specific hard-coded place to save it than 'hObject.Parent'
Jan
el 8 de Feb. de 2017
Or explicitly:
setappdata(ancestor(hObject, 'figure'), 'START', 0)
getappdata(ancestor(hObject, 'figure'), 'START');
Anotehr option would be to use guidata:
function main
handles.FigH = figure;
handles.START = 0;
guidata(handles.FigH, handles);
end
function Callback(hObject, EventData)
handles = guidata(hObject); % Get struct from figure
disp(handles.START)
handles.START = 1;
guidata(hObject, handles); % Store struct in figure
end
mickael robert
el 8 de Feb. de 2017
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!