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

Answers (2)

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 Comment

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.

Sign in to comment.

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.

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Asked:

on 6 Mar 2011

Community Treasure Hunt

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

Start Hunting!