필터 지우기
필터 지우기

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(:)

추가 답변 (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