フィルターのクリア

How to add zero in even position of a matrix

1 回表示 (過去 30 日間)
Soumili Sen
Soumili Sen 2021 年 3 月 20 日
コメント済み: Soumili Sen 2021 年 3 月 20 日
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(:)
  1 件のコメント
Soumili Sen
Soumili Sen 2021 年 3 月 20 日
It's working.Thank u so much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by