How do I add a column to a matrix?

846 ビュー (過去 30 日間)
raj
raj 2012 年 1 月 23 日
編集済み: Randy Souza 2014 年 2 月 13 日
I created a 30x30 matrix and now I want to delete the 1st column of data and add another column replacing the deleted column (which should not replace the same column), so I again get a matrix of size 30x30. I am successful in deleting the 1st column but cannot add another column.

採用された回答

TAB
TAB 2012 年 1 月 23 日
Arr = rand(30,30);
%Delete first column
Arr(:,1) = [];
NewCol = rand(30,1);
%Add new column
Arr = [Arr NewCol];
  3 件のコメント
Image Analyst
Image Analyst 2012 年 1 月 23 日
Depending on *how* you want to do it, you could use interp2, imresize, padarray, etc.
TAB
TAB 2012 年 1 月 23 日
Also see reshape

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 23 日
If you know you are going to delete and add a new column in the same place, then just assign the new data overtop of the old data:
Arr(:,1) = NewData;

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by