Check numbers in a 5x5 array

2 Ansichten (letzte 30 Tage)
STAVROS MANOLIS
STAVROS MANOLIS am 12 Jan. 2022
Kommentiert: Rik am 13 Jan. 2022
I want to write a script that checks if a 5x5 array contains all the numbers from 1 to 25 but im failing to do so. Do you have any ideas?
  1 Kommentar
Jon
Jon am 12 Jan. 2022
Please attach the code you've written and explain the problems (copy and paste error message if any) that you are having

Melden Sie sich an, um zu kommentieren.

Antworten (2)

KALYAN ACHARJYA
KALYAN ACHARJYA am 12 Jan. 2022
Sufficients Hints:
#Check all the elements within 1 & 25, use logical statement to avoid loops
result=data>=.... & data<=....;
#Multiple all elements, if 1 yes, if 0 no
result=prod(result,'all')
  1 Kommentar
Rik
Rik am 13 Jan. 2022
If this is indeed the goal (which I doubt), using the all function instead of prod would probably have a better perfomance.

Melden Sie sich an, um zu kommentieren.


Jon
Jon am 13 Jan. 2022
You can also do this without any loops using MATLAB's intersect function which lists the common elements between two arrays. Hint: if you have two 5x5 arrays and one of them contains the values 1:25 then how many elements will they have in common if the other array also contains the values 1:25

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by