Searching a Matrix for Specific Values

1 visualización (últimos 30 días)
Joe
Joe el 21 de Nov. de 2012
I need to look for occurrences of values in a matrix, namely instances in a matrix where the rows contain the following:
1. The numbers 1 2 3 4 5, in any order 2. the number '2' twice in the same row 3. The row is comprised of entirely the same number.
Thank you
  2 comentarios
Thomas
Thomas el 21 de Nov. de 2012
please show us what you have done so far, and where you are getting stuck.
Joe
Joe el 21 de Nov. de 2012
I was actually able to do the second and third part, but I'm struggling with the first part. I tried using:
ismember([1 2 3 4 5], A, 'rows')
where A the matrix I am searching, however the issue is that I can only search for that specific sequence, not all occurrences of those numbers.

Iniciar sesión para comentar.

Respuestas (1)

John Petersen
John Petersen el 21 de Nov. de 2012
For matrix A
thisrow = A(row,:);
result1 = (any(thisrow,1) && any(thisrow,2) && any(thisrow,3) && any(thisrow,4) && any(thisrow,5));
This will do the first case you posed. result1 will be 1 if the row contains 1,2,3,4,&5, and will be 0 if it doesn't. This should get you started.

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by