Filter löschen
Filter löschen

Adding elements to matrix

1 Ansicht (letzte 30 Tage)
Rajesh
Rajesh am 10 Mär. 2024
Bearbeitet: Matt J am 11 Mär. 2024
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.

Akzeptierte Antwort

Matt J
Matt J am 11 Mär. 2024
Bearbeitet: Matt J am 11 Mär. 2024
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

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by