How to pass parameters between callback (GUI) in different buttongroup

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 Kommentar

Jan
Jan am 8 Feb. 2017
Bearbeitet: Jan am 8 Feb. 2017
Please add any details whenever you use the term "it doesn't work". The observations you make are important to understand and solve the problem. Do you get an error message? Do the results differ from your expectations?

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Adam
Adam am 8 Feb. 2017

1 Stimme

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
Jan am 8 Feb. 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
Thanks for answers !! that help me to find the issue:
Finally i do this:
setappdata(ancestor(hObject, 'figure','toplevel'),'START',1);
getappdata(ancestor(hObject, 'figure','toplevel'),'START');
With 'toplevel' and it work well!!

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 8 Feb. 2017

Beantwortet:

am 8 Feb. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by