How can I resize or scale up a matrix without for loop?

3 views (last 30 days)
Hello,
I have matrix A:
A =
1 2
3 4
and want to resize it to be matrix B. Matrix B should be like this:
B =
1 1 1 2 2 2
1 1 1 2 2 2
1 1 1 2 2 2
3 3 3 4 4 4
3 3 3 4 4 4
3 3 3 4 4 4
My method is an ugly one like this:
A = [1 2;3 4];
scale = 3;
B = [];
[M N] = size(A);
for i = 1:M
for j = 1:N
B((((i-1)*scale)+1):(i*scale),(((j-1)*scale)+1):(j*scale)) = A(i,j);
end
end
So, how can I resize or scale matrix up without using for loop?
Thanks for advice,
K. Pituso

Accepted Answer

Walter Roberson
Walter Roberson on 28 Jul 2015
B = kron(A, ones(3,3));

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!