How to insert a blank column in the matrix

3 ビュー (過去 30 日間)
Racky
Racky 2015 年 7 月 17 日
コメント済み: dpb 2015 年 7 月 17 日
Hi All,
I have a matrix X [1 2 3 4 5]. How do I insert a blank column in between? Eg X = [1 2 3 (blank) 4 5] Thanks,

採用された回答

dpb
dpb 2015 年 7 月 17 日
inPos=4; % location at which to insert
Nz=1; % number of zeros to insert
x=[x(1:inPos-1) repmat(0,1,N) x(nPos:end];
In more general case of an array the subscripts will need to run over all rows using the ":" operator and the above would be the column indices. the '1' argument in repmat would then be the value of size(x,1) of course (or use zeros with appropriate size(s).

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 7 月 17 日
Numeric matrices cannot have blank columns. You can put in any constant value, including -inf, inf, and NaN, but not blank.
Cell arrays can have entries which are the empty matrix.
  1 件のコメント
dpb
dpb 2015 年 7 月 17 日
Good point, Walter; I skimmed over the "blank" reading it as zero w/o even thinking of it...but, I guess it was good enough. :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by