How do I add a column to a matrix?

조회 수: 1,131 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by