function varargout = gradient(f,varargin)
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Jan
il 20 Nov 2019
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Performance and Memory in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!