【问题标题】:How to call a function in Matlab GUI?如何在 Matlab GUI 中调用函数?
【发布时间】:2012-11-09 10:47:58
【问题描述】:

我是 matlab 新手,我试图在 matlab GUI 中调用一个函数,但我一直收到错误消息。你能帮忙吗?

 function PushMe_Callback(hObject, eventdata, handles)
 set(handles.output_line,'String','I Got here');

 Get_Length(Note_Vector,output,Counter,Total_num)
 %------------------------------------------------------------
 function Get_Length(Note_Vector,output,Counter,Total_num)
 output = [ ];
 while (1)
 T = Total_num - Counter;
    for j=1:T
        [xml_input]=Get_Note(Note_Vector(j));
        output = [output xml_input];
    end
 end

【问题讨论】:

  • 错误信息是什么?您的代码在哪一行崩溃?
  • 它返回“未定义变量”然后列出第一个变量 Note_Vector
  • 返回错误信息:- 未定义的函数或变量'Note_Vector'。 AMNR 中的错​​误>PushMe_Callback(第 414 行)Get_Length(Note_Vector,output,Counter,Total_num)
  • 然后你应该定义变量Note_Vector
  • 在main函数中定义,这里是代码 %main function Note_Vector = [ ];输出 = [ ];计数器 = 0; while (1) for i=1:Total_num % % % Note_Vector = [Note_Vector Note+Shift];结束结束

标签: call matlab-guide


【解决方案1】:

您必须从 gui 数据中获取数据。您可以从函数“guidata”中检索这些数据。

实际上发生的情况是,您在“主函数”中定义了一个变量,但您无法访问该变量。

你应该做的是在“GUI_OpeningFcn”函数的句柄中添加这个变量:

Note_Vector = [ ];
output = [ ];
Counter = 0
for i=1:Total_num
    Note_Vector = [Note_Vector Note+Shift];
end
handles.Note_Vector = Note_Vector;
handles.GLoutput = output; %handles.output is already the handle of your GUI, don't change it.
handles.counter=counter;
handles.Total_num=Total_num;
(...)
guidata(hObject, handles);

然后您可以通过简单地编写 handle.Note_Vector 在 PushMe_Callback 中检索这些数据,或者您可以通过在 Get_Length 函数中执行以下操作来检索它们 句柄 = guidata(句柄)。在这种情况下,您必须输入 GUI 的句柄

Get_Length(Note_Vector,output,Counter,Total_num,handles.output)

如果您想了解更多信息,我让您查看有关 guidata() 的 matlab 帮助文件。

【讨论】:

    猜你喜欢
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多