Borrar filtros
Borrar filtros

How to code this command in gui?

3 visualizaciones (últimos 30 días)
Jonathan O'Neill
Jonathan O'Neill el 26 de Ag. de 2014
Comentada: Geoff Hayes el 28 de Ag. de 2014
I have a function I am working on, "SetImage"
[ret] = SetImage(hbin, vbin, hstart, hend, vstart, vend)
I am making a gui that lets you enter each of these parameters into text boxes, once the "set image" button is clicked it will read the data I have typed into the text boxes and use them for each parameter in this function...
I am unaware of how I can set each box to correspond to each individual parameter, this is my attempt to do so:
% --- Executes on button press in setimagebutton.
function setimagebutton_Callback(hObject, eventdata, handles)
% hObject handle to setimagebutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
setimgp1=('handles.setimgh'),('String')
setimgp2=('handles.setimgv'),('String')
setimgp3=('handles.setimgstartc'),('String')
setimgp4=('handles.setimgendc'),('String')
setimgp5=('handles.setimgstartrow'),('String')
setimgp6=('handles.setimgendrow'),('String')
[ret]=SetImage(setimgp1,setimgp2,setimgp3,setimgp4,setimgp5,setimgp6);
The handles are the tags of each of my edit boxes, when I try to run it I receive the error message:
Error using atmcdmex SetImage- parameter 6 is not a number
Error in SetImage (line 25) [ret] = atmcdmex('SetImage', hbin, vbin, hstart, hend, vstart, vend);
Error in CamTestGUI>setimagebutton_Callback (line 1866) [ret]=SetImage(setimgp1,setimgp2,setimgp3,setimgp4,setimgp5,setimgp6);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in CamTestGUI (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)CamTestGUI('setimagebutton_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 27 de Ag. de 2014
Jonathan - you almost have the correct code. You will need to use the get function in order to get the string data from the widget, and then save it to the variable. But since the variables appear to be numeric in nature, you will have to convert them from a string to a number
setimgp1=str2num(char(get(handles.setimgh,'String')));
setimgp2=str2num(char(get(handles.setimgv,'String')));
setimgp3=str2num(char(get(handles.setimgstartc,'String')));
setimgp4=str2num(char(get(handles.setimgendc,'String')));
setimgp5=str2num(char(get(handles.setimgstartrow,'String')));
setimgp6=str2num(char(get(handles.setimgendrow,'String')));
The char function is used to convert the result of the get from a cell to an array of characters (a string). You may or may not need this, but it can't hurt.
Note that if any of the widgets have non-numeric text, then the above conversions may result in an empty matrix being assigned to one of the variables. You may want to add some logic in your code to guard against this happening.
Try the above and see what happens!
  7 comentarios
Jonathan O'Neill
Jonathan O'Neill el 28 de Ag. de 2014
Thanks for all the help Geoff! I have it going now, you had it sorted for me in your earlier posts but I had been editing a redundant "setimage" function in my mfile! So when I clicked "set image" it was running my old code anyway haha.
Sorry about that and thanks for all your help.
Geoff Hayes
Geoff Hayes el 28 de Ag. de 2014
Glad that it worked out!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by