How to resize a matrix repeating the original values N times...

20 views (last 30 days)
Hi all. Im trying to do some sort of UpSample on a matrix, what I need to do is repeat each value of my original matrix N times. Example with N=3
A =
1 2
3 4
A_up =
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
This is going to be used on images of 2Mpx and right now im using matrix concatenation to do it, but it takes more then 10min for each image, and I have to be able to do this in more then 800 images... If someone have a hint of how to do it faster I would be very gratefull.

Accepted Answer

Jan
Jan on 4 Jun 2013
A = [1, 2; ...
3, 4];
B = kron(A, ones(3));

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 4 Jun 2013
Edited: Azzi Abdelmalek on 4 Jun 2013
N=3
out=cell2mat(arrayfun(@(x) ones(N)*x,A,'un',false))
Or
A=[1 2 3;4 5 6;7 8 9]
n=3
m=size(A,1)*n
out=reshape(repmat(reshape(repmat(A(:)',n,1),m,[]),n,1),m,[])

Categories

Find more on Data Type Identification 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!