필터 지우기
필터 지우기

How to get the average for repetitive elements of a matrix?

조회 수: 3 (최근 30일)
Antonio
Antonio 2018년 1월 10일
답변: Sean de Wolski 2018년 1월 10일
Assuming I have a 10x2 matrix, how do I get the average of corresponding values (second column) of repetitive values (first column) in the matrix? Like I have this:
[2 20;
2 30;
2 40;
7 100;
7 110;
7 120;
7 130;
7 140;
15 240;
15 260]
And I want to get this:
[2 30;
7 120;
15 250]

채택된 답변

Sean de Wolski
Sean de Wolski 2018년 1월 10일
m = [2 20;
2 30;
2 40;
7 100;
7 110;
7 120;
7 130;
7 140;
15 240;
15 260]
[uv,~,idx] = unique(m(:,1))
[uv accumarray(idx,m(:,2),[],@mean)]

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by