How to calculate the sum of the numbers that can be divided with 12 for example in a matrix?
3 ビュー (過去 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!