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

조회 수: 3 (최근 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.

채택된 답변

Mischa Kim
Mischa Kim 2017년 11월 10일
편집: Mischa Kim 2017년 11월 10일
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])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by