Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个矩阵
a = [1 2 3 4 5 6 7 8 9 10 11]
我需要将它分成 5 行并用零填充未设置块的其余部分,如下所示:
transformed = [ 1 2 3 4 5 ; 6 7 8 9 10; 11 0 0 0 0 ]
您可以首先扩展a以拥有所需数量的元素,如下所示;
a
a(15) = 0 % Matlab will automatically fill elements 12:14 with 0
然后
transformed = reshape(a,[5,3])'
生产
ans = 1 2 3 4 5 6 7 8 9 10 11 0 0 0 0