MATLAB Answers

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

Asked by SAI KRISHNA CHADA

### SAI KRISHNA CHADA (view profile)

on 10 Nov 2017
Latest activity Commented on by SAI KRISHNA CHADA

### SAI KRISHNA CHADA (view profile)

on 10 Nov 2017
Accepted Answer by Mischa Kim

### Mischa Kim (view profile)

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 Comments

Sign in to comment.

## 1 Answer

### Mischa Kim (view profile)

Answer by Mischa Kim

### Mischa Kim (view profile)

on 10 Nov 2017
Edited by Mischa Kim

### Mischa Kim (view profile)

on 10 Nov 2017
Accepted Answer

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 Comment

SAI KRISHNA CHADA

### SAI KRISHNA CHADA (view profile)

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

Sign in to comment.