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

Jan
Jan 2017년 2월 8일
편집: Jan 2017년 2월 8일
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?

댓글을 달려면 로그인하십시오.

답변 (3개)

Adam
Adam 2017년 2월 8일

1 개 추천

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 2017년 2월 8일
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!!

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2017년 2월 8일

답변:

2017년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by