MATLAB: Submenu & Menu Handling / Reference in Callback Function

menu

Hi, I'm currently trying to reference back to a submenu of a menu that I created using loops. How can I do that?
%Populate / Create Menu & Submenu
FIRST.menu = uimenu('Label','FIRST');
for i = 1:1:length(A)
SECOND.menu = uimenu('Parent',FIRST.menu,'Label',A(i))
for j = 1:1:length(B)
THIRD.menu = uimenu('Parent',SECOND.menu,'Label',B(j))
for k = 1:1:length(C)
THIRD.choices(k) = uimenu(THIRD,'Label',C(k),'Callback',@Callback)
end
end
end
function Callback(eventobject,~)
%How can I reference to a specific submenu in the callback function?
%Like if Option 2 of the FIRST Menu was "expanded" then Option 3 of
%the SECOND Menu was "expanded" and finally Option 4 of the "THIRD"
%Menu was clicked on, how can I refer back to the menus and find out which
%ones were selected(Not the selected options but the respective menus)?

Best Answer

Your THIRD.choices should have 'Parent', THIRD.menu
Within your routine "Callback", you can check the Parent property to trace back to find out what was selected above, and the Parent of that, and so on. And you can check the Label at each level.