Making a simple gui

2 次查看(过去 30 天)
J78246
J78246 2016-6-19
评论: J78246 2016-6-19
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.

采纳的回答

Geoff Hayes
Geoff Hayes 2016-6-19
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.
  1 个评论
J78246
J78246 2016-6-19
Launching it from the command window seemed to do the trick. Thanks, I appreciate it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by