How to make diagonal matrices from a single column
8 次查看(过去 30 天)
显示 更早的评论
I want to make multiple diagonal matrices from a single colimn.
A=[1;2;3;4;5;6;7;8]
From this...
I want to make...
B=[1 0; 0 2]; [3 0; 0 4]; [5 0;0 6]; [7 0;0 8]
Then,
Each diagonal matrix is to be vertically attached.
So, from 10*1 to 10*2.
How can I do that?
Thanks,
0 个评论
采纳的回答
the cyclist
2019-10-14
B = zeros(8,2);
B(1:2:end,1) = A(1:2:end);
B(2:2:end,2) = A(2:2:end);
2 个评论
the cyclist
2019-10-15
编辑:the cyclist
2019-10-15
I think you got some of your math wrong there, but something like this should work:
A = 1:3744;
B = zeros(52,72);
for row = 1:numel(A)
col = mod(ia-1,72) + 1;
B(row,col) = A(row);
end
更多回答(0 个)
另请参阅
类别
在 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!