Filter löschen
Filter löschen

Adding rows to a matrix after every even row

13 Ansichten (letzte 30 Tage)
Harold
Harold am 19 Mai 2013
Is there a way, without using a for loop, to add a row of nan's to a matrix after every even row of the original matrix? For example,
A = [6;2;2;1;1;0;]; %original A matrix will always have an even number of elements
becomes
A = [6;2;NaN;2;1;NaN;1;0];
My initial plane was to make a vector of NaN's having the same size as the final matrix.
temp = nan(size(A,1)/2 - 1,:);

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 19 Mai 2013
Bearbeitet: Azzi Abdelmalek am 19 Mai 2013
A = [6;2;2;1;1;0]
B=[reshape(A,2,[]);nan(1,numel(A)/2)];
B=B(:)

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by