Padding a vector with zeros

조회 수: 3 (최근 30일)
L'O.G.
L'O.G. 2022년 8월 30일
댓글: James Tursa 2022년 8월 30일
How do I pad a vector of type double so that there are say 5 elements with zeros after every 3rd element in the original vector?
For a simple example:
A = [1 2 0.3 2.4 20.3 1.111 6.3 7.1 44];
I want to have
B = [1 2 0.3 0 0 0 0 0 2.4 20.3 1.111 0 0 0 0 0 6.3 7.1 44 0 0 0 0 0];

채택된 답변

David Hill
David Hill 2022년 8월 30일
A = [1 2 0.3 2.4 20.3 1.111 6.3 7.1 44];
b=reshape(A,3,[]);
b=[b;zeros(5,size(b,2))];
B=b(:)';
  댓글 수: 1
James Tursa
James Tursa 2022년 8월 30일
The third line above could also just be:
b(end+5,end) = 0;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by