MATLAB Answers

How do I insert a column with zeros in the second column of a mxn matrix?

조회 수: 27(최근 30일)
Hello, I would like to insert a column with zeros in the second column of a (mxn) matrix, after which the matrix would be a mx(n+1) matrix. It would be really grateful, if someone could help me on this. Thank you.

  댓글 수: 0

로그인 to comment.

채택된 답변

Mischa Kim
Mischa Kim 10 Nov 2017
Mischa Kim 님이 편집함. 10 Nov 2017
Brute force:
A = [1 2 3; 4 5 6; 7 8 9]
A = [zeros(size(A,1),1) A];
A(:,[1 2]) = A(:,[2 1])

  댓글 수: 1

SAI KRISHNA CHADA
SAI KRISHNA CHADA 10 Nov 2017
Thanks a lot for your promt solution. It works! :)

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by