creating a new matrix from an obtained matix?

1 次查看(过去 30 天)
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.

回答(2 个)

Alan Stevens
Alan Stevens 2020-8-15
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 2020-8-15
编辑:metin yilmaz 2020-8-15
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 个评论
metin yilmaz
metin yilmaz 2020-8-15
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by