简体   繁体   English

如何对八度图中文本字段中存储的val求和

[英]how to sum val stored in text field in octave figure

may I ask for help in octave to do summation from textbox by click the button. 我可以通过单击按钮在八度音阶中寻求帮助以从文本框中进行求和。 enclose the form Octave Form 附上表格八度形式

so far my code like this: 到目前为止,我的代码是这样的:

MainFrm = figure(
    "position", [500, 500, 400, 200],
    "color", "blue"
);

TxtA = uicontrol (
   "style", "edit",
   "units", "pixels",
   "string", "INPUT VAL1 HERE",
   "position", [10, 100, 150, 38]
);

TxtB = uicontrol (
   "style", "edit",
   "units", "pixels",
   "string", "INPUT VAL2 HERE",
   "position", [200, 100, 150, 38]
 );

TxtC = uicontrol (
    "style", "edit",
    "units", "pixels",
    "string", "RESULT SHOW HERE",
    "position", [200, 50, 150, 38]
);

CmdSumm = uicontrol(
  MainFrm,
  "style", "pushbutton",
  "string", "SUMMATION",
  "units", "pixels",
  "position", [10, 50, 150, 38]
);

function Summation (hObject, eventdata, AddFrame)
  uicontrol(AddFrame);
  TxtC = TxtA + TxtB
end

what I want to do is: user can put value in textbox1 and textbox2. 我想做的是:用户可以将值放在textbox1和textbox2中。 after the user inputed the value on both textbox user click or press the summation button to execute summation proses. 在用户在两个文本框上输入值后,用户单击或按下求和按钮以执行求和。 the result then show / display in textbox3. 结果然后在textbox3中显示/显示。

how to do this in octave? 如何在八度中做到这一点? thank you for your kind attention. 感谢您的关注。

I'd suggest going through Octave's GUI documentation again. 我建议再次浏览Octave的GUI文档 While not necessarily as comprehensive as they could be, there's a few things there that would have gotten you further along. 虽然不一定像它们可能的那样全面,但仍有一些事情会让您更进一步。

  • First issue: your Summation function lacks references to the edit box objects, so it can't get the values 第一个问题:您的Summation函数缺少对编辑框对象的引用,因此无法获取值
  • Second issue: your pushbutton has no callback , so clicking it won't do anything 第二个问题:您的按钮没有回调 ,因此单击它不会做任何事情
  • Third "issue": No idea what AddFrame is, or why it's an input to Summation 第三个“问题”:不知道什么AddFrame是,为什么它是一个输入Summation

For the first issue, you'll want to use a function like guidata to store the handles to your graphics objects in a way that is accessible by the rest of the UI. 对于第一个问题,您将想要使用guidata类的功能,以UI其余部分可以访问的方式将图形对象的句柄存储在其中。 To do so, store the outputs of your UI object creation calls to a structure, then save that structure to your main figure for later use. 为此,请将UI对象创建调用的输出存储到一个结构中,然后将该结构保存到您的主图中以供以后使用。 You can obtain the structure with another call of guidata 您可以通过调用guidata获得结构

For the second issue, you need to specify Summation as the callback function for your pushbutton so it is executed on button press. 对于第二个问题,您需要将Summation指定为按钮的回调函数,以便在按下按钮时执行它。

The updated code would look something like this: 更新后的代码如下所示:

function aGUI()
h.MainFrm = figure(
    "position", [500, 500, 400, 200],
    "color", "blue"
);

h.TxtA = uicontrol (
   "style", "edit",
   "units", "pixels",
   "string", "INPUT VAL1 HERE",
   "position", [10, 100, 150, 38]
);

h.TxtB = uicontrol (
   "style", "edit",
   "units", "pixels",
   "string", "INPUT VAL2 HERE",
   "position", [200, 100, 150, 38]
 );

h.TxtC = uicontrol (
    "style", "edit",
    "units", "pixels",
    "string", "RESULT SHOW HERE",
    "position", [200, 50, 150, 38]
);

h.CmdSumm = uicontrol(
  h.MainFrm,
  "style", "pushbutton",
  "string", "SUMMATION",
  "units", "pixels",
  "position", [10, 50, 150, 38],
  "Callback", @Summation
);

guidata(h.MainFrm, h)
end

function Summation(hObject, eventdata)
h = guidata(hObject);
C = str2double(get(h.TxtA, 'String')) + str2double(get(h.TxtB, 'String'));
set(h.TxtC, 'String', C)
end

Which functions as desired. 哪个功能符合要求。

While not specifically Octave, I'd also recommend checking out MATLAB's UI documentation . 虽然不是专门的Octave,但我也建议您查阅MATLAB的UI文档 It's fairly comprehensive and the syntax should be more or less equivalent to what you'd find in Octave. 它相当全面,语法应该或多或少与您在Octave中找到的语法相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM