How to calculate the sum of the numbers that can be divided with 12 for example in a matrix?
조회 수: 2 (최근 30일)
이전 댓글 표시
How to calculate the sum of the numbers that can be divided with 12 for example in a matrix? Should I use a while or for loop?
R=randi([107 167],1,57)
댓글 수: 2
James Tursa
2017년 10월 3일
편집: James Tursa
2017년 10월 3일
You should use a mod() or rem() with logical indexing and a sum(). Were you instructed to use a loop for this exercise?
Image Analyst
2017년 10월 3일
All numbers can be divided by 12. I assume you mean with no remainder, so James answer should work.
답변 (2개)
Linus Michelin
2021년 9월 27일
I did it like this:
S=0;
for R=randi([107 167],1,57)
if mod(R,12)==0
S=S+R;
else S=S;
end
end
S
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!