Info

This question is closed. Reopen it to edit or answer.

How to make gui alter variables in the base area?

1 view (last 30 days)
Hi, I am in the process of forming a gui to retrieve data from a camera, and enable the user to set certain settings for the camera before running a set of tests. I have asked a question before on this but I am stuck again...
Can someone explain to me how I edit settings in the main matlab base from the gui please? For example, I have created a tab named "program settings", and I want to choose which "acquisition mode" to run when I start the camera. It has a few values from 1,2,3,4,5, etc all linking to a different setting. How can I code so that whatever setting I choose in the list edits the value in the main matlab base making the camera run with this property?
Sorry if this is simple I am new to gui and don't have much experience with matlab.
I have attached some images to try and illustrate what I am talking about
Thanks
  2 Comments
Adam
Adam on 19 Aug 2014
Edited: Adam on 19 Aug 2014
I'm not sure I fully understand what you are trying to do.
In general you shouldn't be trying to change variables in the base workspace from a GUI.
The GUI has its own data associated with it and a workspace of sorts through the handles structure that is attached to the gui and is passed to every callback.
You can attach whatever data you want to this handles structure, always making sure that you call guidata( hObject, handles ) or guidata( gcbo, handles ) at the end of your function to update the GUI's handles structure to that of your currently executing callback.
That means you can set some parameter in the callback of one GUI component and access that parameter from the callback of another GUI component. Or using listeners or direct access via handles to other GUI components you can trigger actions from a GUI component's callback.
For example you could put all those program settings onto the handles structure, e.g.
handles.readMode = get( handles.editBox1, 'String' )
or whatever kind of UI control you have.
Then wherever you trigger off your camera from can access these parameters from the handles structure.
Jonathan O'Neill
Jonathan O'Neill on 20 Aug 2014
Edited: Jonathan O'Neill on 20 Aug 2014
Maybe my lack of experience is making my question hard to understand, sorry. So if I use the editor with the gui I can choose a parameter to run without having to go back to the base to edit it?
For example, In the main workspace I have coded SetReadMode has four potential settings...
[ret]=SetReadMode(4); % 0 = FVB 1 = Multi-Track 2 = Random-Track 3 = Single-Track
With the gui I would like a list menu that enables me to choose which read mode to run, this will then overwrite the previous ReadMode setting. Should I use an "if" statement to do this?
if list1=fvb then SetReadMode(0)
Something like this?
edit: _
% --- Executes on selection change in acmode.
function acmode_Callback(hObject, eventdata, handles)
% hObject handle to acmode (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 acmode contents as cell array
% contents{get(hObject,'Value')} returns selected item from acmode
_Single_Scan=1
Accum=2
Kinetics=3
Fast_Kin=4
Run_til_Abort=5
items = get(hObject,'String');
index_selected = get(hObject,'Value');
item_selected = items{index_selected};
display(item_selected);
if item_selected==1;
SetAquisitionMode(1);
end
if item_selected==2;
SetAquisitionMode(2);
end
if item_selected==3;
SetAquisitionMode(3);
end
if item_selected==4;
SetAquisitionMode(4);
end
if item_selected==5;
SetAquisitionMode(5);
end__
this is code I have made to set the acquisition mode on the camera, do you think this makes sense?

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!