버전 (10.6 KB) 작성자: John D'Errico
Consolidates common elements in x (may be n-dimensional), aggregating corresponding y.
다운로드 수: 10.4K
업데이트 날짜: 2007/9/10

라이선스 보기

Consolidator has many uses. It was designed to solve an interpolation problem and a Delaunay problem, but I've added other uses too. It can serve as a tool which counts the number of replicates of each point, or as simply an implementation of unique(x,'rows'), but with a tolerance on that unique-ness.

Interpolation fails when there are replicate x values. Often it is recommended to form the mean of y for the replicate x values, eliminating the reps. Consolidator does this, and allows a tolerance on how close two values of x need be to be considered replicates. x may have multiple columns, i.e., it works on multi-dimensional data. x may even be a character array.

This same problem is seen both in interp1 and in griddata. Delaunay and delaunayn are also not robust when called with data that has replicates or near replicates.

Example usages:

% counting replicates
x = round(rand(100000,1)*2);
[xc,yc] = consolidator(x,[],'count');
ans =
0 25160
1 49844
2 24996

% aggregate y for the unique elements in x
% y = x(:,1) + x(:,2) + error
x = round(rand(100000,2)*2);
y = sum(x,2)+randn(size(x,1),1);
[xc,yc] = consolidator(x,y,'mean');
ans =
0 0 0.0054
0 1.0000 0.9905
0 2.0000 1.9895
1.0000 0 0.9957
1.0000 1.0000 1.9970
1.0000 2.0000 2.9988
2.0000 0 2.0136
2.0000 1.0000 2.9985
2.0000 2.0000 3.9891

Alternate usage using a function handle:
[xc,yc] = consolidator(x,y,@mean);

The aggregation can also be of many types. Min, max, mean, sum, std, var, median, prod, as well as geometric and harmonic means, plus the simple count option. Use of a function handle allows for
any aggregation the user may desire.

Consolidator is very different from accumarray.
Note that accumarray builds a potentially huge
array, filled with zeros. This array cannot be sparse in higher than 2 dimensions. Also, accumarray does not allow a tolerance. Its first argument MUST be an index. Finally, consolidator works on strings too.

인용 양식

John D'Errico (2024). Consolidator (, MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R14SP1
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
Help CenterMATLAB Answers에서 ANOVA에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보

Provided count information as a 4th output