Comparing single element of one array with values of another array
显示 更早的评论
I have an array A which is mx1. I have a second array, B, which is nx2. I would like to find the values of A which fall in between the two values of B in each row.
for k = 1:size(B,1);
[row, col] = find(A>=B(k,1)&&A=<B(k,2));
end
When I run this I run into two problems.
1) A>=B(k,1) (or the other inequality) throws an error about matrix dimension mismatch. I know that I can compare A>=a where a is a single double value, so why does it cause a problem when I am comparing against a single value of the other matrix? Is it possible to work around this without creating a new variable with just that value?
2) I have problems using the && or expressions. I am able to create two different logical variables on either side of the expression (like in the sample code, pretending it works), but when placed together the error, "Operands to the and && operators must be convertible to logical scalar values," is produced. It seems to me that the && and expressions only seem to work with single logical expressions, rather than arrays of logical results. Is this true?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!