Matrix whose elements are the colums numbers
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to create a 100*100 matrix with 3 conditions :
- elements on the diagonal are 0
- elements below the diagonal contain the column number
- elements above the diagonal contain the column number with minus sign
it may look simple but I am really new here so I hope someone could help me out :)
thanks in advance
0 个评论
回答(1 个)
David Hill
2021-3-12
n=100;
[a,b]=ind2sub([n,n],1:n^2);
b(b==a)=0;
b(b>a)=-b(b>a);
c=reshape(b,[n,n]);
2 个评论
David Hill
2021-3-12
If you a satisfied with the answer, you should accept it to close out the question.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!