Effacer les filtres
Effacer les filtres

How to add zero in even position of a matrix

1 vue (au cours des 30 derniers jours)
Soumili Sen
Soumili Sen le 20 Mar 2021
Commenté : Soumili Sen le 20 Mar 2021
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.

Réponse acceptée

Alan Stevens
Alan Stevens le 20 Mar 2021
Like this
a = [1;2;3;4];
z = zeros(size(a));
b = [a';z'];
b = b(:)
  1 commentaire
Soumili Sen
Soumili Sen le 20 Mar 2021
It's working.Thank u so much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by