SUMM

版本 1.1.0.0 (1.8 KB) 作者: Andy
Function analogous to DIFF, but takes sums instead.
375.0 次下载
更新时间 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 CenterMATLAB Answers 中查找有关 Operators 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