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 view (last 30 days)
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.

Answers (1)

Michael Madelaire
Michael Madelaire on 26 Oct 2017
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

Products

Community Treasure Hunt

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

Start Hunting!