Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
matlab从GUI按钮运行脚本文件_Matlab_Matlab Figure_Matlab Guide - Fatal编程技术网

matlab从GUI按钮运行脚本文件

matlab从GUI按钮运行脚本文件,matlab,matlab-figure,matlab-guide,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) gu

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

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

function pushbutton2_Callback(hObject, eventdata, handles)
run('classifyDeeb.m')
或者不带分机叫它。只要它位于Matlab的路径中,它就可以工作

function pushbutton2_Callback(hObject, eventdata, handles)
classifyDeeb

我尝试使用两个选项:无错误,但脚本文件未运行,我可以从命令窗口运行它您确定它未运行吗?在classifyDeeb.m的最开始添加一行,类似于
disp(“我正在运行”)
并查看它是否打印到命令行。我怀疑它正在运行,但你们有一些其他类型的问题。也是你们不知道的情况。如果您使用这样的GUI运行脚本,它将不会看到默认工作区中的变量。它将在按钮功能范围内运行。因此,如果脚本依赖于工作区中的变量,它将无法工作。它正在运行并显示(我正在运行),但不会运行真正的代码,正如您所说,脚本依赖于工作空间中的变量。我有一个变量作为矩阵文件(deeb.mat)。如何让它运行?感谢您的帮助将矩阵包含为
句柄的字段,并将其作为脚本的输入发送(这应该成为一个函数)