How to populate "pop-up" menu based on a variable in an edit box

9 views (last 30 days)
I have an editbox that displays the number of cameras I have connected to my computer, at the minute I have just manually placed:
1
2
3
4
as the string to my popup menu which lets the user select which camera to activate. How can I fill this popup menu based on how many cameras are connected? So, for example if I have two connected the string of my popup menu automatically displays:
1
2
And if I have 4:
1
2
3
4
I have a box that displays the number of cameras connected, so I just have to link the popup menu to this editbox?

Accepted Answer

Geoff Hayes
Geoff Hayes on 28 Oct 2014
Jonathan - how is the text box populated with the number of connected cameras? I think that whenever this text box is updated, you would do the same for the popup menu. Something like
% suppose the number of connected cameras is 12
numConnectedCameras = 12;
% update the text box
set(handles.text1,'String',num2str(numConnectedCameras));
% update the popup menu
set(handles.popupmenu1,'String',num2str((1:numConnectedCameras)'));
If the user decides on the number of connected cameras (by entering a number in the edit box) then in its callback, you would add the third line from the above (after initializing numConnectedCameras with the contents from the edit box).
  1 Comment
Jonathan O'Neill
Jonathan O'Neill on 28 Oct 2014
Thanks Geoff, it was populated by this code:
[ret,NoOfCams]=GetAvailableCameras;
set(handles.NoCam,'String',NoOfCams);
So I just added this under it:
set(handles.SelCampopup,'String',num2str((1:NoOfCams)'));
Now when I find out how many cameras are connected to the computer it automatically populates this popup menu, cheers!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!