Am unable to wrap my head on this question regarding for loop , can someone explain the question and maybe write the code please.
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796174/image.png)
1 个评论
采纳的回答
Awais Saeed
2021-11-10
Why use a loop if it can be done without it
A = [1 2 3; 4 5 6; 7 8 9];
[sum_of_elements] = halfsum(A)
function [sum_of_elements] = halfsum(M)
A = M;
sum_of_elements = sum(triu(A), 'all');
end
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!