Inserting a constant array in between each of the coloumns
1 回表示 (過去 30 日間)
古いコメントを表示
Hi All,
Looking for a help on simple problem (New to Matlab)
Question:
I have an (M * N) matrix; now, I want to insert a constant array {1 * N} (say all 1's) in between each of the N columns.
Is there an easy way to do that.
Help is much appreciated.
Thanks a lot.
0 件のコメント
回答 (1 件)
Roger Stafford
2013 年 12 月 4 日
You can't place a 1 x N row vector between columns - it wouldn't fit. So I assume you really mean place it between rows. If that is what you mean, do this. Let the M x N matrix be A and the 1 x N array be B.
A(1:2:2*M-1,:) = A;
A(2:2:2*M-2,:) = repmat(B,M-1,1);
If by any chance you really want to place something between the columns, you would need an N x M matrix and an N x 1 constant array, that is, a column vector, and you would have to reverse the columns and rows in the above code.
2 件のコメント
Roger Stafford
2013 年 12 月 4 日
You originally asserted that your constant array was 1 x N which is a row vector. I'm glad you changed to an M x 1 column vector here, which would indeed fit between columns.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!