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

Antworten (2)

Paulo Silva
Paulo Silva am 6 Mär. 2011

0 Stimmen

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 Kommentar

Jos (10584)
Jos (10584) am 7 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Matt Tearle
Matt Tearle am 6 Mär. 2011

0 Stimmen

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.

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 6 Mär. 2011

Community Treasure Hunt

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

Start Hunting!

Translated by