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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Michael Madelaire
el 26 de Oct. de 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
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!