概述
今天我在运行matlab程序的时候遇到了这个报错,现在解决了,给大家讲一讲怎么解决的。
首先这个问题在csdn上已经有些人讲过了,他们遇到的原因大多是自己本身就有同样名字的.m文件。
但是我这个就比较特别。大家可以先观察一下,如果你的报错尝试将 SCRIPT surf作为函数执行:后面的文件地址是在E:MATLABR2018btoolboxmatlabgraph3d这种类别的地方,那你就去按照这个路径去检查一下,你的surf文件是不是空的。
我这个软件本身就是在网上下的,可能有些漏洞,所以我下载以后我的surf.m文件压根就是空的,自然也就引用不了。如果是这个问题的话,大家复制一下surf.m的源代码放在那个空的文件里面就可以运行了。
我把源代码就放在下面了,有需要的朋友复制一下即可。
function h = surf(varargin)
%SURF 3-D colored surface.
% SURF(X,Y,Z,C) plots the colored parametric surface defined by
% four matrix arguments. The view point is specified by VIEW.
% The axis labels are determined by the range of X, Y and Z,
% or by the current setting of AXIS. The color scaling is determined
% by the range of C, or by the current setting of CAXIS. The scaled
% color values are used as indices into the current COLORMAP.
% The shading model is set by SHADING.
%
% SURF(X,Y,Z) uses C = Z, so color is proportional to surface height.
%
% SURF(x,y,Z) and SURF(x,y,Z,C), with two vector arguments replacing
% the first two matrix arguments, must have length(x) = n and
% length(y) = m where [m,n] = size(Z). In this case, the vertices
% of the surface patches are the triples (x(j), y(i), Z(i,j)).
% Note that x corresponds to the columns of Z and y corresponds to
% the rows.
%
% SURF(Z) and SURF(Z,C) use x = 1:n and y = 1:m. In this case,
% the height, Z, is a single-valued function, defined over a
% geometrically rectangular grid.
%
% SURF(...,'PropertyName',PropertyValue,...) sets the value of the
% specified surface property. Multiple property values can be set
% with a single statement.
%
% SURF(AX,...) plots into AX instead of GCA.
%
% SURF returns a handle to a surface plot object.
%
% AXIS, CAXIS, COLORMAP, HOLD, SHADING and VIEW set figure, axes, and
% surface properties which affect the display of the surface.
%
% See also SURFC, SURFL, MESH, SHADING.
%-------------------------------
% Additional details:
%
% If the NextPlot axis property is REPLACE (HOLD is off), SURF resets
% all axis properties, except Position, to their default values
% and deletes all axis children (line, patch, surf, image, and
% text objects).
% Copyright 1984-2016 The MathWorks, Inc.
% J.N. Little 1-5-92
narginchk(1,inf)
[~, cax, args] = parseplotapi(varargin{:},'-mfilename',mfilename);
nargs = length(args);
hadParentAsPVPair = false;
if nargs > 1
% try to fetch axes handle from input args,
% and allow it to override the possible input "cax"
for i = 1:length(args)
if ~isempty(args{i}) && ischar(args{i}) && strncmpi(args{i}, 'parent', length(args{i})) && nargs > i
cax = args{i+1};
hadParentAsPVPair = true;
break;
end
end
end
% Error if given uiaxes
if isa(cax,'matlab.ui.control.UIAxes')
restrictedAccess = 1;
try
restrictedAccess = feature('WebGraphicsRestriction');
catch
%Do nothing.
end
if restrictedAccess
error(message('MATLAB:ui:uiaxes:general'));
end
end
% do input checking
dataargs = parseparams(args);
error(surfchk(dataargs{:}));
% use nextplot unless user specified an axes handle in pv pairs
% required for backwards compatibility
if isempty(cax) || ~hadParentAsPVPair
if ~isempty(cax) && ~ishghandle(cax,'Axes')
parax = cax;
cax = ancestor(cax,'Axes');
hold_state = true;
else
cax = newplot(cax);
parax = cax;
hold_state = ishold(cax);
end
else
cax = newplot(cax);
parax = cax;
hold_state = ishold(cax);
end
% We need to separate out convenience arguments from P/V pairs:
% First, determine the number of numeric data arguments:
len = length(args);
n = 1;
while n<=len && isplottable(args{n})
n = n+1;
end
n = n-1;
% Determine the appropriate syntax:
params = {};
switch(n)
case 1
% SURF(Z,...)
z = args{1};
matlab.graphics.internal.configureAxes(cax,[],[],z);
[~,~,z] = matlab.graphics.internal.makeNumeric(cax,[],[],z);
params = {'ZData',z};
args = args(2:end);
case 2
% SURF(Z,C,...)
z = args{1};
matlab.graphics.internal.configureAxes(cax,[],[],z);
[~,~,z] = matlab.graphics.internal.makeNumeric(cax,[],[],z);
params = {'ZData',z,'CData',args{2}};
args = args(3:end);
case 3
% SURF(X,Y,Z,...)
x = args{1};
y = args{2};
z = args{3};
matlab.graphics.internal.configureAxes(cax,x,y,z);
[x,y,z] = matlab.graphics.internal.makeNumeric(cax,x,y,z);
params = {'XData',x,'YData',y,'ZData',z};
args = args(4:end);
case 4
% SURF(X,Y,Z,C,...)
x = args{1};
y = args{2};
z = args{3};
matlab.graphics.internal.configureAxes(cax,x,y,z);
[x,y,z] = matlab.graphics.internal.makeNumeric(cax,x,y,z);
params = {'XData',x,'YData',y,'ZData',z,'CData',args{4}};
args = args(5:end);
end
%Place parenting arguments first so that parent-sensitive properties
%eg. UIContextMenu are set after surface is parented.
allargs = [params, {'Parent',parax}, args];
hh = matlab.graphics.chart.primitive.Surface(allargs{:});
if ~hold_state
view(cax,3);
grid(cax,'on');
end
if nargout == 1
h = hh;
end
% function out=id(str)
% out = ['MATLAB:surf:' str];
function out = isplottable(x)
out = isnumeric(x) || isa(x,'datetime') || isa(x,'duration');
最后
以上就是飞快八宝粥为你收集整理的使用matlab遇到 “尝试将 SCRIPT surf作为函数执行:的全部内容,希望文章能够帮你解决使用matlab遇到 “尝试将 SCRIPT surf作为函数执行:所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复