File Exchange

image thumbnail

Average and remove duplicates from a matrix

version 1.0 (1.39 KB) by

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

1 Download


View License

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

Comments and Ratings (4)

John D'Errico

John D'Errico (view profile)

John D'Errico

John D'Errico (view profile)

Incredibly slow.

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

Elapsed time is 58.442939 seconds.

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.

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

Jos (10584)

Jos (10584) (view profile)

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.

MATLAB Release
MATLAB 7.9 (R2009b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today