How do I add a column to a matrix?

997 visualizaciones (últimos 30 días)
raj
raj el 23 de En. de 2012
Editada: Randy Souza el 13 de Feb. de 2014
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.

Respuesta aceptada

TAB
TAB el 23 de En. de 2012
Arr = rand(30,30);
%Delete first column
Arr(:,1) = [];
NewCol = rand(30,1);
%Add new column
Arr = [Arr NewCol];
  3 comentarios
Image Analyst
Image Analyst el 23 de En. de 2012
Depending on *how* you want to do it, you could use interp2, imresize, padarray, etc.
TAB
TAB el 23 de En. de 2012
Also see reshape

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 23 de En. de 2012
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;

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by