Adding rows to a matrix after every even row

6 ビュー (過去 30 日間)
Harold
Harold 2013 年 5 月 19 日
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,:);

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 19 日
編集済み: Azzi Abdelmalek 2013 年 5 月 19 日
A = [6;2;2;1;1;0]
B=[reshape(A,2,[]);nan(1,numel(A)/2)];
B=B(:)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by