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
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 Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!