Reputation: 75
We have a data set X n*m matrix and I want to create a matrix like this W=[0 X;X' 0] how should I do that in Matlab?
A=[1 2;3 4];
B=[0 A;A' 0];
what's wrong with that code?
Upvotes: 1
Views: 462
Reputation: 18838
Because the size of 0
is not the as A
and A'
in row and column.
You can create a matrix with the size of what you want:
B = zeros(2*size(A));
and replace the value where you want:
B(1:2, 3:4) = A;
B(3:4, 1:2) = A.';
Upvotes: 0
Reputation: 30047
You just need to use zeros
to make sure the dimensions agree
A = [1 2; 3 4];
z = zeros( size( A ) );
B = [ z, A; A', z ];
Upvotes: 1