Reputation: 176
I have a matrix A=(1 2; 3 4)
, and I want to augment A
to B = (1 2 0; 3 4 0; 0 0 0)
, what can I do ?
One way is: B = [[A, zeros(2,1)]; zeros(1,3)]
But it might be clumsy in a dynamic process, any other ideas ?
Upvotes: 2
Views: 908
Reputation: 4650
Also:
padarray(A,[1 1],'post')
Output:
ans =
1 2 0
3 4 0
0 0 0
It's a little more versatile and makes the semantics very clear.
Upvotes: 1
Reputation: 36710
B=A
B(3,3)=0
Matlab fills the other elements automatically with zeros
Upvotes: 5