Delete Lines if there are three e qual lines

Hi, i have this problem. I have a matrix A(m ; 8). I would have new Matrix B where are delete the Lines Whith this idea: if in matrix A There are three Numbers that are the same in Colomn 3 and 5, in the new Matrix delete this three Lines.

7 comentarios

madhan ravi
madhan ravi el 29 de Oct. de 2018
give an example
Giuseppe Antonacci
Giuseppe Antonacci el 29 de Oct. de 2018
for example i have this matrix A=[ 1 3 7 8 9 7 2 8 ; 9 0 3 5 2 1 4 9 ; 0 2 3 6 2 7 7 7 ; 3 2 3 5 2 2 5 7 ] .
in the second, third e forth lines there are the same number in the third e fiveth colomn for this reason i would delate all lines.
madhan ravi
madhan ravi el 29 de Oct. de 2018
What’s your desired output give an example
Giuseppe Antonacci
Giuseppe Antonacci el 29 de Oct. de 2018
in this case A=[ 1 3 7 8 9 7 2 8 ; 9 0 3 5 2 1 4 9 ; 0 2 3 6 2 7 7 7 ; 3 2 3 5 2 2 5 7 ] B=[ 1 3 7 8 9 7 2 8 ] becouse in the other lines there are the same numbers in colomn three and five.
KSSV
KSSV el 29 de Oct. de 2018
It is not clear.....you need to explain more...
jonas
jonas el 29 de Oct. de 2018
Editada: jonas el 29 de Oct. de 2018
Let me guess
A =
1 3 7 8 9 7 2 8
9 0 3 5 2 1 4 9
0 2 3 6 2 7 7 7
3 2 3 5 2 2 5 7
Delete rows where three or more (consecutive???) columns share the same value? Clarify:
  • consecutive duplicates only?
  • limit the check to columns 3 & 5?
  • exactly three duplicates or more than three?
  • is the matrix always 4 rows?
  • What if only column 3 has consecutive duplicates? Or only column 5?
To summarize: I don't think you have thought this through.
Giuseppe Antonacci
Giuseppe Antonacci el 29 de Oct. de 2018
this matrix in an example. the matrix is (m;8). the first three point in correct.

Respuestas (1)

Stephen23
Stephen23 el 29 de Oct. de 2018
Editada: Stephen23 el 29 de Oct. de 2018
This should get you started:
>> A = [1,3,7,8,9,7,2,8;9,0,3,5,2,1,4,9;0,2,3,6,2,7,7,7;3,2,3,5,2,2,5,7]
A =
1 3 7 8 9 7 2 8
9 0 3 5 2 1 4 9
0 2 3 6 2 7 7 7
3 2 3 5 2 2 5 7
>> B = [1,3,7,8,9,7,2,8] % expected output
B =
1 3 7 8 9 7 2 8
>> X = diff(A(:,[3,5]),1,1)==0;
>> Y = X(1:end-1,:) & X(2:end,:);
>> Z = any(conv2(Y,[1;1;1])>0,2); % either column 3 OR 5
>> B = A(~Z,:)
B =
1 3 7 8 9 7 2 8
If you want both columns to fit the condition:
Z = all(conv2(Y,[1;1;1])>0,2)

1 comentario

madhan ravi
madhan ravi el 29 de Oct. de 2018
Cool @ Stephen was struggling to figure it out thanks

La pregunta está cerrada.

Preguntada:

el 29 de Oct. de 2018

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by