Retrieving minimum values for parts of a matrix
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I have a matrix containing different rows with values for several years. I need to retrieve the minimum value corresponding to each year. For example: A=[ 1958 2; 1958 3; 1959 4; 1959 5; 1959 6 ] The result matrix that I need would be: B=[ 1958 2; 1959 4 ]
Could you please help with this? Thanks
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2016년 5월 17일
편집: Azzi Abdelmalek
2016년 5월 17일
A=[ 1958 2; 1958 3; 1959 4; 1959 5; 1959 6 ]
[ii,jj,kk]=unique(A(:,1))
out=[ii accumarray(kk,(1:numel(kk))',[],@(x) min(A(x,2)))]
댓글 수: 0
추가 답변 (1개)
Matt J
2016년 5월 17일
편집: Matt J
2016년 5월 17일
[i,~,s]=find( accumarray(A(:,1), A(:,2),[],@min ) );
B=[i,s]
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!