Making a simple gui
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
J78246
el 19 de Jun. de 2016
Comentada: J78246
el 19 de Jun. de 2016
I need to make a gui for another purpose, but I have never made one before in Matlab, so I figured I should make a test gui first. So I tried to make a simple gui that adds two numbers. I created 3 edit boxes and a push button that would execute the addition of boxes 1 and 2 when pressed. I give all the edit boxes the tags number1, number2, and number3 respectively. I then go to the callback function for the button and insert the following code:
a=get(handles.number1,'string');
b=get(handles.number2,'string');
a=str2double(a);
b=str2double(b);
c=a+b;
set(handles.number3,'string',num2str(c))
It keeps giving me an error for the very first line of that code (Struct contents reference from a non-struct array object). I have tried everything I could think of to make this work. I tried using str2num instead of str2double. I tried using the default tags and handles. I followed multiple tutorials that all essentially insert the code that I inserted. Oddly enough, it worked the first time I made it, but then when I came back to it it kept giving me this error. So at this point I don't what to do anymore.
0 comentarios
Respuesta aceptada
Geoff Hayes
el 19 de Jun. de 2016
J78246 - I observe that same error message if I launch the GUI by opening the .fig file. When you do this, only the figure with the GUI controls appears. None of the normal or needed initializations occur, so the structure handles is not a structure. It doesn't even exist.
You can launch a GUIDE created GUI by calling the m file from the Command Window as
>> myGui
where myGui corresponds to the m and fig files named myGui.m and myGui.fig respectively. You can also launch the GUI by pressing the green run button in the GUI figure editor or by pressing the green run button in the MATLAB m-file editor.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks 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!