How to use uicontrol and callback for a user-defined input flow?

조회 수: 5 (최근 30일)
Davi
Davi 2014년 11월 22일
댓글: Davi 2014년 11월 23일
I have being dealing with the following problem: in a GUI, user enters a number N. That creates two sets of N popupmenus. popup1 controls popup2: Let's say popup1 has options '1', '2' and '3'. If option '1' in popup1 is selected, popup2 menu should be 'A', 'B' and 'C', if '2' is selected in popup1, popup2 should be 'M', 'N' and 'P' and if option '3' is selected in popup1, popup2 should be 'X', 'Y' and 'Z'.
I have tried to use uicontrol and callback, and it creates the popups. The problem is that I don't know how to access the variables inside the popups. Does anyone know how to do this?

채택된 답변

Orion
Orion 2014년 11월 22일
In the callback of popup1, you just want to modify the string in popup2.
I guess you need something like :
function popup1_callback(hObject,eventdata,handles)
Value1 = get(handles.popup1,'Value');
if Value1==1
List = {'A';'B';'C'};
elseif Value1==2
List = {'M';'N';'P'};
else
List = {'X';'Y';'Z'};
end
set(handles.popup2,'String',List);
  댓글 수: 9
Orion
Orion 2014년 11월 23일
I copy/pasted a wrong line in the previous/previous code.
I pasted
function popup1_callback(hObject, eventdata)
handles = guihandles(gcf);
instead of
function popup1_callback(hObject, eventdata)
handles = guidata(gcf);
this works
Davi
Davi 2014년 11월 23일
It does! Thanks a lot!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 11월 23일
Or use this framework where you can just plug your code into the callbacks for various sliders, listboxes, etc. http://www.mathworks.com/matlabcentral/fileexchange/24224
  댓글 수: 1
Davi
Davi 2014년 11월 23일
Hello Image Analyst, Thanks for your reply. If i understand it correctly, in all examples you sent the objects are defined before runtime, which would make my life a lot easier. The problem I have is that the popups will have to be created at runtime and I am struggling to access the handles in this case. Would you have an example where user enters N, two sets of N popups are created and popup1 controls popup2?

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by