Finding indices in matrix with find() function

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

Réponses (2)

Paulo Silva
Paulo Silva le 6 Mar 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 commentaire

Jos (10584)
Jos (10584) le 7 Mar 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.

Connectez-vous pour commenter.

Matt Tearle
Matt Tearle le 6 Mar 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.

Catégories

En savoir plus sur Simulink dans Centre d'aide et File Exchange

Tags

Question posée :

le 6 Mar 2011

Community Treasure Hunt

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

Start Hunting!

Translated by