%SUMM Sum of consecutive pairs in an array, analogous to DIFF.
% SUMM(X), for a vector X, is [X(2)+X(1) X(3)+X(2) ... X(n)+X(n-1)].
% SUMM(X), for a matrix X, is the matrix of row sums,
% [X(2:n,:) + X(1:n-1,:)].
% SUMM(X), for an N-D array X, is the sum along the first
% non-singleton dimension of X.
% SUMM(X,N) is the N-th order sum along the first non-singleton
% dimension (denote it by DIM). If N >= size(X,DIM), SUMM takes
% successive sums along the next non-singleton dimension.
% SUMM(X,N,DIM) is the Nth sum function along dimension DIM.
% If N >= size(X,DIM), SUMM returns an empty array.
%
% Examples:
%
% If X = [3 7 5
% 0 9 2]
% then summ(X,1,1) is [3 16 7], summ(X,1,2) is [10 12
% 9 11],
% summ(X,2,2) is the 2nd order sum along the dimension 2, and
% summ(X,3,2) is the empty matrix.
%
% Note: There's probably a better way to do this. In testing, this
% is consistently three times slower than diff. But it was quick
% enough.
%
% This was inspired by the CSSM question:
% http://www.mathworks.com/matlabcentral/newsreader/view_thread/259947
Cita come
Andy (2025). SUMM (https://www.mathworks.com/matlabcentral/fileexchange/25208-summ), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.