How do i use the edit text box in a GUI to change variables in a function that i run with the gui???
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Richard
el 13 de Jun. de 2014
0 votos
3 comentarios
Geoff Hayes
el 13 de Jun. de 2014
Hi Richard - the Attempt to reference field of non-structure array error message is thrown when the code treats a variable as if it were a structure and tries to access some element of it. In this case, the line of code is handles.Ss. I think that handles may be empty (not set) because if it wasn't then either this line of code would work or throw the Reference to non-existent field 'Ss' message.
You may need to put a breakpoint at this line and then re-start the GUI and press the button. If handles is empty, then something has not been set quite right earlier in the code.
Also, look at the code for initialization for your GUI (initial block) and that for the __OpeningFcn too. There may have been an unexpected change to one or both of these functions that could result in this type of problem.
Richard
el 13 de Jun. de 2014
Geoff Hayes
el 13 de Jun. de 2014
Awesome!
As for the char, I needed that in my version (2014a) because the result of the get(handles.editSs,'String') was a cell..so I needed to convert it to a string/char array. I haven't seen anyone else do that (in other pieces of code) so maybe it isn't necessary for you and is just something specific to the way I set something up.
Categorías
Más información sobre Entering Commands en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!