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.

回答(1 个)

Michael Madelaire
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

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by