How to extend/add elements to an array?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rikke
am 15 Apr. 2019
Kommentiert: Rikke
am 17 Apr. 2019
I want to extend an array at the points were the array are 0.
For example an array like this:
A=[2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ];
At each zero in A i want to extend by B=[3 2 3 5];
so the new array will be:
C=[2 3 4 5 0 0 0 1 4 5 5 0 0 3 4 0 0 0 2 0 0 0 0 0];
0 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 15 Apr. 2019
Bearbeitet: Andrei Bobrov
am 16 Apr. 2019
A = [2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ];
B = [3 2 3 5];
out = A(sort([find(A),repelem(find(A == 0),B)]));
4 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Matrices and 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!