How to erase data from a matrix from the command line?

3 visualizaciones (últimos 30 días)
INTRO: Hi, I have a matrix Mij and would like to erase the rows i whenever the row-value of two columns are identical (for example:Mi2=Mi3)
Example:
M=3 1.2 13 2
1.2 0.3 0.3 10
10 2 1 0
0.7 5 3 0.4
The new matrix
Nij= 3 1.2 13 2
10 2 1 0
0.7 5 3 0.4
I wonder if someone could help me how to solve this issue
Thanks in advance
Emerson

Respuesta aceptada

Matt Fig
Matt Fig el 26 de Oct. de 2012
M=[3 1.2 13 2
1.2 0.3 0.3 10
10 2 1 0
0.7 5 3 0.4];
Nij = M(all(diff(sort(M,2),[],2),2),:)
  5 comentarios
Matt Fig
Matt Fig el 26 de Oct. de 2012
Same idea:
M = [1 2 3 4;5 6 7 8;1 2 3 3;6 7 8 9;3 4 5 5];
M(~diff(M(:,3:4),[],2),:) = []
Emerson De Souza
Emerson De Souza el 26 de Oct. de 2012
Now I got it, thank you for your attention
Wish you a nice night
Emerson

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by