Can someone talk me through making matlab use values from a popup box when I press a button?

1 view (last 30 days)
Hi, I have created a GUI and am trying to tidy up my code to make changes easier. Basically I have a button that runs my code, which I set all of my variables/settings etc.. within. Instead of having this list of code that a user needs to edit for a certain test I made a GUI with popup menus in order to select them. Can someone explain to me how I go about using the settings picked in my popup menu within my main "previmage" button?
example:
% --- Executes on button press in previmage.
function previmage_Callback(hObject, eventdata, handles)
% hObject handle to previmage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp('iCam Live Mode Preview')
PrepareAcquisition()
% init system
disp('Initialising Camera');
ret=AndorInitialize('');
CheckError(ret);
disp('Configuring Acquisition');
[ret]=CoolerON(); % Turn on temperature cooler
CheckWarning(ret);
[ret]=SetAcquisitionMode(5); % Set acquisition mode; 5 for RTA
CheckWarning(ret);
[ret]=SetExposureTime(0.02); % Set exposure time in second
CheckWarning(ret);
[ret]=SetReadMode(4); ****************************%Set read mode***********************
CheckWarning(ret);
[ret]=SetTriggerMode(10); % Set Software trigger mode
useSoftwareTrigger = true;
As you can see to select the read mode for my camera you must go into this code and change the value "4" to the desired mode from "0" to "4".(each number setting a different read mode) To make life easier I made a popup menu in my GUI that lets you pick which readmode is activated.
This is the code for the popup menu:
% --- Executes on selection change in Read_mode.
function Read_mode_Callback(hObject, eventdata, handles)
% hObject handle to Read_mode (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Read_mode contents as cell array
% contents{get(hObject,'Value')} returns selected item from Read_mode
FVB=0;
Multi_Track=1;
Random_Track=2;
Single_Track=3;
Image=4;
items = get(hObject,'String');
index_selected = get(hObject,'Value');
item_selected = items{index_selected};
if item_selected==0;
SetReadMode(0);
end
if item_selected==1;
SetReadMode(1);
end
if item_selected==2;
SetReadMode(2);
end
if item_selected==3;
SetReadMode(3)
end
if item_selected==4;
SetReadMode(4)
end
How can I replace "setreadmode(4)" in my "previmage" button with a line of code that takes whatever has been selected from this popup menu instead?
Thanks

Accepted Answer

Adam
Adam on 15 Sep 2014
get( handles.Read_mode, 'Value' )
should give you the index of the currently selected option in your popup list.
  11 Comments
Jonathan O'Neill
Jonathan O'Neill on 16 Sep 2014
Cheers, one more question... Should I not define what each of the values in the popup menu are qual to?
ie: FVB =1 Multi-Track=2 etc
Or does matlab just automatically assume that FVB is equal to the value of 1?
Its just that if I select any other readmode matlab runs into a loop and doesn't display an image at all, although this is more than likely due to some other error on my part
Adam
Adam on 16 Sep 2014
Your SetReadMode function presumably has the interpretation of the raw values as FVB or Multi Track or whatever.
In the popup list that interpretation comes from the order in which you put the string of options together for the popup list. This must be the same as the order you interpret them as in your function.
The loop issue sounds like a different problem though.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!