SUMM

Versione 1.1.0.0 (1,83 KB) da Andy
Function analogous to DIFF, but takes sums instead.
375 download
Aggiornato 3 set 2009

Visualizza la licenza

%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 (2024). SUMM (https://www.mathworks.com/matlabcentral/fileexchange/25208-summ), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2009a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Operators and Elementary Operations in Help Center e MATLAB Answers
Tag Aggiungi tag

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.1.0.0

Took into account several excellent suggestions by Jan Simon, including correct handling of empty matrices. Thanks!

1.0.0.0