Code covered by the BSD License  

Highlights from
nancumsum

5.0

5.0 | 2 ratings Rate this file 22 Downloads (last 30 days) File Size: 2.43 KB File ID: #14895

nancumsum

by Brett Shoelson

 

07 May 2007 (Updated 05 Oct 2011)

Compute the cumulative sum of matrices, specifying the treatment of NaNs.

| Watch this File

File Information
Description

nancumsum: Cumulative sum of a matrix, with user-specified treatment of NaNs.
      
Computes the cumulative sum of matrix A along dimension DIM, allowing the user to replace NaNs with zeros, to skip over them, or to reset on NaNs, maintaining NaNs as placeholders.
 
USAGE: B = nancumsum(A, DIM, NMODE)
 
ARGUMENTS:
 
A: Input matrix.
 
B: Output cumulative sum matrix, treating NaNs as determined by nmode.
 
DIM: B = nancumsum(A, DIM) returns the nan-cumulative sum of the elements
along the dimension of A specified by scalar DIM. For example,nancumsum(A,1) works down the columns, nancumsum(A,2) works across the rows. If DIM is not specified, it defaults to the first non-singleton dimension of A.
 
NMODE: specifies how NaNs should be treated. Acceptable values are:
1: REPLACE NaNs with zeros (default).
2: MAINTAIN NaNs as position holders in B. (Skip NaNs without reset.)
3: RESET sum on NaNs, replacing NaNs with zeros.
4: RESET sum on NaNs, maintaining NaNs as position holders.
  
See also: cumsum, nansum, nancumprod, nanmean, nanmedian, ...
(nancumprod is available from the FEX. Other nan* may require Toolboxes)

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
07 May 2007 John D'Errico

As you should expect from Brett, excellent in all respects.

09 May 2007 Urs (us) Schwarz

a trouvaille of paramount importance to this community - offered by former CSSM senior brett shoelson; a function that should have been in ML stock for a long time.
needless to say that his clean coding fulfills all the criteria to be a five-star contender: concise h1, help text with meticulous examples, proper input and options error checking, and an interesting, vectorized engine.
us

Please login to add a comment or rating.
Updates
08 May 2007

Fixing bug in my code (isvector should have been isscalar) and in my examples(thanks, us). Also updating See also references.

09 May 2007

Fixing a bug (failed for scalar inputs).

04 May 2010

added copyright

21 Jun 2010

Updated M file and license text file copyright to The MathWorks, Inc.

29 Aug 2011

This submission fixes a bug pointed out by a couple of attentive users. Also, note that I have added new options for the treatment of NaNs, and eliminated one for special treatment of vectors. (Not necessary!)

05 Oct 2011

Fixes an issue with the vectorization of mode 3.

Tag Activity for this File
Tag Applied By Date/Time
nan Brett Shoelson 22 Oct 2008 09:11:59
cumulative Brett Shoelson 22 Oct 2008 09:11:59
sum Brett Shoelson 22 Oct 2008 09:11:59
cumsum Brett Shoelson 22 Oct 2008 09:11:59

Contact us at files@mathworks.com