How can I add zeros between elements of a matrix?
82 次查看(过去 30 天)
显示 更早的评论
I have a vector [1,2,3];
and I want to obtain [1,0,2,0,3,0];
How can this be achieved?
0 个评论
回答(2 个)
Stephen23
2020-8-31
>> A = [1,2,3];
Method one: indexing:
>> B = zeros(size(A).*[1,2]);
>> B(1:2:end) = A
B =
1 0 2 0 3 0
Method two: reshape:
>> B = A;
>> B(2,:) = 0;
>> B = B(:).'
B =
1 0 2 0 3 0
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!