问题是:
Product of known dimensions, 3, not divisible into total number of elements, 16.
这一点,因为我想reshape
一个16x1
在矩阵3x6
的矩阵。问题是起始矩阵有16个元素,而最终矩阵有18个元素。是否存在一种聪明的方法来按行整形并用0填充丢失的元素,直到元素数量匹配?
当然,我需要一种独立于这些数字的通用方法,因为矩阵的大小可以改变。
TBN:0应该在矩阵的末尾
您可以将vec2mat
其用作“通讯系统工具箱”的一部分,并假设A
输入向量-
ncols = 6; %// number of columns needed in the output
out = vec2mat(A,ncols)
样品运行-
>> A'
ans =
4 9 8 9 6 1 8 9 7 7 7 4 6 2 7 1
>> out
out =
4 9 8 9 6 1
8 9 7 7 7 4
6 2 7 1 0 0
如果您没有该工具箱,则可以使用基本功能来实现相同功能-
out = zeros([ncols ceil(numel(A)/ncols)]);
out(1:numel(A)) = A;
out = out.'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句