Hello i am not good at matlab at all and i am trying to make a GUI work like i want it too. I want to be able to change values in my function from the GUI before I run the GUI. This is code i want to run in the GUI and the Ss and SR are the variables i want to be able to control from the GUI.
function AutofocusGUI(Ss , SR) Ss=.01; SR=5; Fvar=[]; h.MoveAbsoluteEx (0,0,1,0); % home
pause(3) for z = 0:Ss:SR % Step size and Sweep range
h.MoveAbsoluteEx (0,z,1,0); pause(.75) frame = getsnapshot(vid); frame=frame(160:320, 240:400); Fvar=[Fvar std2(im2double(frame))]; end pause(2) figure(3) z = 0:Ss:SR plot(z,Fvar) % graph of step and variance
xlabel('z') ylabel('variance') pause(2) maxFvar=max(Fvar); [mmaxFvar , ind] = max(Fvar); maxX= z(ind); h.MoveAbsoluteEx (0,maxX,1,0);end
I was able to get the GUI to run AutofocusGUI(Ss, SR) code with the variables Ss and SR defined in the code and it worked great but i was not able to control Ss and SR. This is what i did.
% — Executes on button press in StartAutofocus.
function StartAutofocus_Callback(hObject, eventdata, handles)% hObject handle to StartAutofocus (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
AutofocusGUI(Ss,SR);end
What should i do now to be able to control the values of Ss and SR from my edit text box in the GUI before I press the StartAutofocus button to start the function.
Best Answer