I have three columns containing data. I want to isolate particular data depending on the third column and find the maximum values on the second column for each case of the isolated data from the third column.
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a matrix with the following form:
A = [1 2 3; 2 2 6; 0 1 3; 0 4 3]
I want for each unique case from the third column, to find the maximum values on the first and the second columns.
댓글 수: 0
답변 (1개)
Michael Madelaire
2017년 10월 26일
Hi, hope this works.
The first column shows the max in the first column.
The second column shows the max in the second column.
The third column shows the unique values in AA.
A = [1 2 3; 2 2 6; 0 1 3; 0 4 3];
[values, tag, places] = unique(A(:, 3));
AA = zeros(length(values), 3);
AA(:, 3) = values;
for i = 1:length(values)
AA(i, 1) = max(A(places == tag(i), 1));
AA(i, 2) = max(A(places == tag(i), 2));
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!