Q:
I have the following matrix:
[1 5
4 9]
What's the fastest way, and without a for loop, to expand it to:
[1 1 5 5
1 1 5 5
4 4 9 9
4 4 9 9]
A1:
A = [1 4; 5 9] ;
kron(A, ones(3)) ;
A2:
idx = cumsum(ones(2),2 )
B = A(idx, idx)
A3:
[m, n] = size(A);
mdup = 4;
ndup = 3;
vx = ceil((1:m*mdup)/mdup);
vy = ceil((1:n*ndup)/ndup);
B = A(vx, vy)
A4:
[m,n] = size(A);
mdup = 4;
ndup = 3;
AX = repmat(A, [1 1 mdup ndup]);
AX = permute(AX, [3 1 4 2]);
AX = reshape(AX, m*mdup, n*ndup);
No comments:
Post a Comment