matlab从GUI按钮运行脚本文件

时间:2018-06-02 12:01:15

标签: matlab matlab-figure matlab-guide

我有一个脚本文件,想从gui按钮运行它 它不起作用。

错误是:

Undefined variable "classifyDeeb" or class "classifyDeeb.m".

Error in Train>pushbutton2_Callback (line 113)
classifyDeeb.m
Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in Train (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)Train('pushbutton2_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback

------------------
 scrip file code `load deeb;
trdata=[deeb(1:8,2:6);deeb(11:18,2:6)];
gr=[deeb(1:8,1);deeb(11:18,1)];
testdata=[deeb(9:10,2:6);deeb(19:20,2:6)];
svmstr=svmtrain(trdata,gr);
result = svmclassify(svmstr,testdata);
output = result;`
----------------------------
the pushbutton2_Callback code is :

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
classifyDeeb.m

脚本文件,图形和矩阵数据(deeb.mat)文件位于同一文件夹中。 请帮忙 提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

两种选择: 您可以在m文件名上使用run()。如果脚本位于另一个目录中,您甚至可以包含脚本的完整路径。

function pushbutton2_Callback(hObject, eventdata, handles)
run('classifyDeeb.m')

或在没有扩展名的情况下调用它。只要它位于Matlab的路径上,它就会起作用。

function pushbutton2_Callback(hObject, eventdata, handles)
classifyDeeb