creating a new matrix from an obtained matix?

3 visualizaciones (últimos 30 días)
metin yilmaz
metin yilmaz el 15 de Ag. de 2020
Comentada: Alan Stevens el 15 de Ag. de 2020
Hello. If I already have a matrix [1 2 3; 4 5 6; 7 8 9], how can I add 0 to its every row by a command?
Thank you.

Respuestas (2)

Alan Stevens
Alan Stevens el 15 de Ag. de 2020
Something like:
M = [1 2 3; 4 5 6; 7 8 9];
Mplus = [M zeros(3,1)]
Mplus =
1 2 3 0
4 5 6 0
7 8 9 0
Alwys assuming you want the zeros as the last column.

metin yilmaz
metin yilmaz el 15 de Ag. de 2020
Editada: metin yilmaz el 15 de Ag. de 2020
Thank you Alan Stevens but what If I wanted 2s, or twos, as the first column instead of 0s, or zeros, as the last one?
  5 comentarios
metin yilmaz
metin yilmaz el 15 de Ag. de 2020
Would you please explain how to add a new column as the third one inside your matrix, sliding your previous 3th, and 4th and 5th to the right? That is you will have a new matrix having one more column.
Thank you.
Alan Stevens
Alan Stevens el 15 de Ag. de 2020
Try:
M = [M(:,1:2) 2*ones(3,1) M(:,3:end)];

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices 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