Problem with find and logical array
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
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?
采纳的回答
更多回答(2 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!