SUMM

バージョン 1.1.0.0 (1.83 KB) 作成者: Andy
Function analogous to DIFF, but takes sums instead.
ダウンロード: 375
更新 2009/9/3

ライセンスの表示

%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

引用

Andy (2024). SUMM (https://www.mathworks.com/matlabcentral/fileexchange/25208-summ), MATLAB Central File Exchange. 取得済み .

MATLAB リリースの互換性
作成: R2009a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersOperators and Elementary Operations についてさらに検索
タグ タグを追加

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.1.0.0

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

1.0.0.0