필터 지우기
필터 지우기

How can I add zeros between elements of a matrix?

조회 수: 43 (최근 30일)
Lucrezia Cester
Lucrezia Cester 2020년 8월 31일
답변: Stephen23 2020년 8월 31일
I have a vector [1,2,3];
and I want to obtain [1,0,2,0,3,0];
How can this be achieved?

답변 (2개)

Stephen23
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

madhan ravi
madhan ravi 2020년 8월 31일
reshape([vector; zeros(size(vector))], 1, [])

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by