How to Copy Upper diagonal elements of matrix A into a new matrix.
19 次查看(过去 30 天)
显示 更早的评论
A= 1 2 3 4; 2 1 3 4; 1 1 1 2; 1 0 0 1 Then how to copy the upper diagonal elements into a new Matrix using for loops etc.
0 个评论
采纳的回答
更多回答(2 个)
Awais Saeed
2021-9-14
编辑:Awais Saeed
2021-9-14
A= [1 2 3 4; 2 1 3 4; 1 1 1 2; 1 0 0 1]
M = zeros(size(A));
for row = 1:1:size(A,1)
for col = row:1:size(A,2)
M(row,col) = A(row,col);
end
end
disp(M)
4 个评论
Awais Saeed
2021-9-14
I answered exactly as per your question "how to copy the upper diagonal elements into a new Matrix using for loops".
Why do you care how your developer is doing things. If you think he is making a mistake or he needs help in doing what you asked in your question then just simply show him the proposed answer. If he does not like doing it in a For Loop then use triu(A) as @Jan have mentioned.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!