Problem with find and logical array

조회 수: 3 (최근 30일)
Urvashi
Urvashi 2014년 6월 6일
편집: Urvashi 2014년 6월 6일
Hi,
I have a matrix with the values : A = [260,343; 344,433; 434,530; 531,631; 632,723];
where A(:,1) is the lower range and A(:,2) = upper range for each row. I am trying to find the index of A where a number may exist within the upper and lower range.
For ex. I tried B = (443 > A(:,1) & A(:,2) > 443) to check in which row the number 443 would lie, but got the ans as 0, even though when B comes as = [0,0,1,0,0]. I performed index = find(B),
I am probably doing something stupid. What am I doing wrong?
Thanks, Urvashi
  댓글 수: 3
Urvashi
Urvashi 2014년 6월 6일
I know. I will download 'find' again. May be it's a problem with my function
Geoff Hayes
Geoff Hayes 2014년 6월 6일
What do you mean by "download 'find' again"? Are you using a different version of find from the built-in one?

댓글을 달려면 로그인하십시오.

채택된 답변

Sara
Sara 2014년 6월 6일
편집: Sara 2014년 6월 6일
You could do:
B = find(443 > A(:,1) & A(:,2) > 443);
B is the row or rows where the condition is satisfied.
  댓글 수: 2
Urvashi
Urvashi 2014년 6월 6일
I did that too, and still got the answer as B = 0. There might be something wrong with the function 'find' in my version. I should probably download it again.
Sara
Sara 2014년 6월 6일
Yeah, could be, because everybody here is getting the right result.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 6월 6일
I don't see any problem:
A = [260,343; 344,433; 434,530; 531,631; 632,723]
targetValue = 443
logicalRowsInRange = (targetValue > A(:,1) & A(:,2) > targetValue)
rowInRange = find(logicalRowsInRange)
A =
260 343
344 433
434 530
531 631
632 723
targetValue =
443
logicalRowsInRange =
0
0
1
0
0
rowInRange =
3

Urvashi
Urvashi 2014년 6월 6일
편집: Urvashi 2014년 6월 6일
Yeah, thanks a lot. It worked. I had missed a ) in one of my previous statements of find, so find ended up being an empty matrix. And I didn't realize that the variable find was generated as there was a huge list of variables being generated during the program run.
My bad. Really, my bad.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by