Check numbers in a 5x5 array
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Jon
2022년 1월 12일
Please attach the code you've written and explain the problems (copy and paste error message if any) that you are having
답변 (2개)
KALYAN ACHARJYA
2022년 1월 12일
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
Rik
2022년 1월 13일
If this is indeed the goal (which I doubt), using the all function instead of prod would probably have a better perfomance.
Jon
2022년 1월 13일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!