logical operation on matrix
1 view (last 30 days)
Show older comments
(Return logical 0 or 1) if matrix A contains ten values between 500 and 600.
A=[1 2 3;4 5 6; 4 5 2]
A(A>[1:2:6])=true %SMALL NUMBERS FOR EXAMPLE
0 Comments
Accepted Answer
DGM
on 8 Mar 2022
I'm going to assume that the text question is what you're after:
A = randi([100 999],10,10) % a bunch of integers
mk = A>=500 & A<=600 %find locations in the specified range
has10inrange = nnz(mk)>=10 % are there at least 10 values in the range?
1 Comment
Image Analyst
on 8 Mar 2022
Or if you want to know if "A contains ten values between 500 and 600"
has10inRange = nnz(mk) == 10 % has10inRange is true if there are exactly 10 values in the range.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!