function varargout = gradient(f,varargin)

1 次查看(过去 30 天)
dear all.
excuse me,
Need help in parse_inputs , when I write it I faced error
[f,ndim,loc,rflag] = parse_inputs(f,varargin);
nargoutchk(0,ndim);
Not enough input arguments.
% Loop over each dimension.
varargout = cell(1,ndim);
siz = size(f);
% first dimension
g = zeros(size(f),class(f)); % case of singleton dimension
h = loc{1}(:);
n = siz(1);
% Take forward differences on left and right edges
if n > 1
g(1,:) = (f(2,:) - f(1,:))/(h(2)-h(1));
g(n,:) = (f(n,:) - f(n-1,:))/(h(end)-h(end-1));
end
% Take centered differences on interior points
if n > 2
h = h(3:n) - h(1:n-2);
g(2:n-1,:) = bsxfun(@rdivide,(f(3:n,:)-f(1:n-2,:)),h);
end
varargout{1} = g;
% second dimensions and beyond
if ndim == 2
% special case 2-D matrices to support sparse matrices,
% which lack support for N-D operations including reshape
% and indexing
n = siz(2);
h = reshape(loc{2},1,[]);
g = zeros(size(f),class(f));
% Take forward differences on left and right edges
if n > 1
g(:,1) = (f(:,2) - f(:,1))/(h(2)-h(1));
g(:,n) = (f(:,n) - f(:,n-1))/(h(end)-h(end-1));
end
  1 个评论
Jan
Jan 2019-11-20
What is the relation between the error message and the posted code? Please post the real snippet of the code, which contains the failing command and explain, how you call this function.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by