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 Comment

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?

Sign in to comment.

Answers (3)

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'
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!!

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 8 Feb 2017

Answered:

on 8 Feb 2017

Community Treasure Hunt

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

Start Hunting!