Code covered by the BSD License  

Highlights from
Average and remove duplicates from a matrix

3.5

3.5 | 2 ratings Rate this file 12 Downloads (last 30 days) File Size: 1.39 KB File ID: #34952

Average and remove duplicates from a matrix

by Mitchell Olson

 

06 Feb 2012

This function averages out duplicate values in a matrix and removes the duplicates

| Watch this File

File Information
Description

This function finds duplicate values along the first column of a matrix, averages the remaining rows, and removes the duplicate rows.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
08 Feb 2012 Jos (10584)

This might be useful to some. However, you should a look at accumarray:

[u,i,j] = unique(A(:,1)) ;
A_avg_dup = [j, accumarray(j,A(:,2),[],@mean)] ;

In addition, you might revise your help section, so that it mimics ML standards (H1 line, used by LOOKFOR, a SEE ALSO line). Take a look at the help of any basic ML function for some inspiration.

01 May 2012 rasam aliazizi

Thank you, this is exctly what i was looking for.

01 May 2012 John D'Errico

Incredibly slow.

X = round(rand(1e6,1)*10000);

tic,avg_dup(X);toc
Elapsed time is 58.442939 seconds.

tic,consolidator(X);toc
Elapsed time is 0.609666 seconds.

And it is not terribly useful, since it

1. Looks for exact replicates, with no capability for a tolerance.

2. Allows the capability to average only. If you want to compute instead the sum, or max, min, harmonic mean, median, geometric mean, standard deviation, etc., you are out of luck.

There is no H1 line, merely a statement of the author's name and e-mail address. That means the lookfor tool is disabled when you forget what the name of this tool is next year.

I'd suggest a tool that offers everything this does and far more, allowing you to compute any aggregative measure, has better help, an H1 line, and is seriously faster.

http://www.mathworks.com/matlabcentral/fileexchange/8354-consolidator

01 May 2012 John D'Errico  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
duplicate Mitchell Olson 07 Feb 2012 09:26:45
data processing Mitchell Olson 07 Feb 2012 09:26:45

Contact us at files@mathworks.com