increase the length of a martix every 5 rows
古いコメントを表示
Dear all,
I have a matrix (double array) of dimension 40000 by 7 and I want to increase the length of this matrix every 5 rows by adding a cell NaN.
For instance, if I have initially
A=[2.4332 4.1477;
2.6073 4.5900;
2.2310 3.7442;
2.4555 4.1178;
2.5096 4.1946;
2.7517 4.7802;
2.8372 4.9423;
2.9577 5.1563;
3.2365 5.6061;
3.0658 5.3787;
2.9244 5.0497;
2.6104 4.4623;
2.5419 4.4164;
2.4947 4.3577;
2.5633 4.7050
]
then I want
A=[2.4332 4.1477;
2.6073 4.5900;
2.2310 3.7442;
2.4555 4.1178;
2.5096 4.1946;
NaN NaN
2.7517 4.7802;
2.8372 4.9423;
2.9577 5.1563;
3.2365 5.6061;
3.0658 5.3787;
NaN NaN
2.9244 5.0497;
2.6104 4.4623;
2.5419 4.4164;
2.4947 4.3577;
2.5633 4.7050;
NaN NaN
]
I am looking for an efficient code (1-2 lines if possible)
thank you very much
採用された回答
その他の回答 (1 件)
Azzi Abdelmalek
2012 年 8 月 5 日
編集済み: Walter Roberson
2012 年 8 月 5 日
% this code is for test the example
B=reshape(A,5,2,3);B(6,:,:)=nan;result= reshape(B,18,2)
% this code is for your real data
B=reshape(A,5,7,1400);B(6,:,:)=nan;result= reshape(B,8400,7)
% note that 1400 = 7000/5; and 8400=(5+1)*1400
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!