首页 > 解决方案 > matlab 从 GUI 按钮运行脚本文件

问题描述

我有一个脚本文件,想从 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) 文件位于同一文件夹中。请帮助提前感谢您的帮助

标签: matlabmatlab-figurematlab-guide

解决方案


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

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

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

function pushbutton2_Callback(hObject, eventdata, handles)
classifyDeeb

推荐阅读