Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How can i get the output?

1 visualización (últimos 30 días)
VIJAY
VIJAY el 14 de Sept. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
i have the matrix
A=[1 2 4;
1 2 3;
4 5 6;
7 8 9;
4 5 8;
9 1 3];
i hope to compare first two column only comparison in the matrix so i need the output as
A=[7 8 9;
9 1 1]
  1 comentario
KSSV
KSSV el 14 de Sept. de 2017
How this output comes?

Respuestas (1)

Rik
Rik el 14 de Sept. de 2017
I'm going out on a limb here: I will assume your question is how to remove all rows where the first two values are non-unique. This rephrasing immediately points to the solution: use the unique function with the 'row' switch and the additional output (the position). Then we count occurrences with hist and remove all rows with an occurrence not equal to 1.
A=[1 2 4;
1 2 3;
4 5 6;
4 5 8;
9 1 3;
7 8 9];
[~,indexInMatrix,positionOfRowInUniqueVector]=unique(A(:,1:2),'rows','stable');
[numOfOccurrences,~]=hist(positionOfRowInUniqueVector,unique(positionOfRowInUniqueVector,'stable'));
rowIndex=indexInMatrix(numOfOccurrences==1);
A=A(rowIndex,:);

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by