Code covered by the BSD License  

Highlights from
Accumulate Connected Components

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 2.11 KB File ID: #21397

Accumulate Connected Components

by Wolfgang Schwanghart

 

10 Sep 2008 (Updated 10 Sep 2008)

Construct array with accumulation of connected components

| Watch this File

File Information
Description

accumconncomps creates vectors by accumulating elements in one vector using the connected components in another vector of same size. Connected components are regarded as subsequent, identical elements in a vector.

Example:
Sum the values in val according to the connected components in cc.
 
cc = [1 1 2 1 1 1 3 3 3 4 2 2];
val = [2.3 1.2 5 3 2 5 3.2 4.5 2 ...
       2.2 1.2 2.2];
  
[c,valnew] = accumconncomps(cc,val,@sum)
  
c = 1 2 1 3 4 2
valnew = 3.5 5.0 10.0 9.7 2.2 3.4

I know, the function is rather simple, but needed it several times and perhaps others do so as well. In case you have a better way to code it, or in case you have any suggestion for an improved help text, please let me know.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
accumarray Wolfgang Schwanghart 22 Oct 2008 10:18:40
connected components Wolfgang Schwanghart 22 Oct 2008 10:18:40
general Wolfgang Schwanghart 22 Oct 2008 10:18:40
mathematics Wolfgang Schwanghart 22 Oct 2008 10:18:40
accumarray Faisal Shahzad 09 Feb 2009 12:30:25

Contact us at files@mathworks.com