MATLAB: How to populate “pop-up” menu based on a variable in an edit box

guiguidepopup menu

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?

Best Answer

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).