logical operation on matrix

1 Ansicht (letzte 30 Tage)
Faisal Al-Wazir
Faisal Al-Wazir am 8 Mär. 2022
Kommentiert: Image Analyst am 8 Mär. 2022
(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 = 3×3
1 2 3 4 5 6 4 5 2
A(A>[1:2:6])=true %SMALL NUMBERS FOR EXAMPLE
A = 3×3
1 2 3 1 1 1 1 1 2

Akzeptierte Antwort

DGM
DGM am 8 Mär. 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
A = 10×10
756 350 720 933 311 504 214 315 736 279 334 959 539 277 582 701 528 418 941 523 768 367 470 157 524 543 177 131 833 416 995 572 341 728 828 280 875 161 250 482 201 593 316 296 813 148 341 356 435 870 392 162 693 700 398 301 509 438 390 533 284 593 774 286 710 781 976 337 833 527 616 751 880 961 804 339 626 177 588 956 946 771 904 346 665 560 106 544 366 708 320 446 804 673 429 882 836 850 224 371
mk = A>=500 & A<=600 %find locations in the specified range
mk = 10×10 logical array
0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0
has10inrange = nnz(mk)>=10 % are there at least 10 values in the range?
has10inrange = logical
1
  1 Kommentar
Image Analyst
Image Analyst am 8 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by