How to add zero in even position of a matrix

1 次查看(过去 30 天)
hello,
Suppose I have a matrix
N=5; %can be anything
a=randi([1 4],N,1);
So I am getting a result like a=[1 2 3 2 4]'.
Now I want to add zeros in the even position, so my desired output will be b=[1 0 2 0 3 0 2 0 4 0]'
How I can implement this in the matlab?
Thanks in advance.

采纳的回答

Alan Stevens
Alan Stevens 2021-3-20
Like this
a = [1;2;3;4];
z = zeros(size(a));
b = [a';z'];
b = b(:)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by