Adding elements to matrix

조회 수: 4 (최근 30일)
Rajesh
Rajesh 2024년 3월 10일
편집: Matt J 2024년 3월 11일
I have [1 2 3 4 5 6 7 8 9 10]. I want the new matrix [0 1 2 0 3 4 0 5 6 0 7 8 0 9 10 0] that is I need to add zero after each two elements.

채택된 답변

Matt J
Matt J 2024년 3월 11일
편집: Matt J 2024년 3월 11일
A=[1 2 3 4 5 6 7 8 9 10]
A = 1×10
1 2 3 4 5 6 7 8 9 10
B=[reshape(A,2,[]); zeros(1,numel(A)/2)];
B=[0,B(:)'] %the result
B = 1×16
0 1 2 0 3 4 0 5 6 0 7 8 0 9 10 0

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by