Finding indices in matrix with find() function

2 visualizaciones (últimos 30 días)
Alexis
Alexis el 6 de Mzo. de 2011
Hi all,
I'm having some difficulty using the find() function with multiple conditions. Below is a sample of what I'm referring to. LUTi and LUTj are matrices with defined values.
>> LUTi(60,240)
ans =
0
>> LUTj(60,240)
ans =
1.0000
>> [theta1 theta2] = find(LUTi == 0 & LUTj == 1)
theta1 =
Empty matrix: 0-by-1
theta2 =
Empty matrix: 0-by-1
The output I'm expecting to see is [60,240], but instead, it's returning an empty matrix. Am I inputting the 2 conditions incorrectly? Thank you in advance.
Alexis

Respuestas (2)

Paulo Silva
Paulo Silva el 6 de Mzo. de 2011
You are using the find function in two matrices at the same time, that's not a good idea
[row column]=find(LUTi==0)
[row1 column1]=find(LUTj==1)
  1 comentario
Jos (10584)
Jos (10584) el 7 de Mzo. de 2011
Why not?
I assume that both matrices have the same size (otherwise an error would have been trhown by AND) and Alexis is looking for the indices where both comparisons are true.

Iniciar sesión para comentar.


Matt Tearle
Matt Tearle el 6 de Mzo. de 2011
I think you may have fallen for an old trap. Please enter
1 - LUTj(60,240)
and see what the result is. I'm going to take a guess that it's not 0. Given the way it says LUTj(60,240) is "1.0000", I'm guessing that the value is not exactly 1, but 1 + some roundoff. In that case, testing ==1 will return false. The solution is to test something like
abs(x - 1) < tol
where tol is some small value.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by