How to resize a matrix repeating the original values N times...
14 views (last 30 days)
Show older comments
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.
2 Comments
Accepted Answer
Jan
on 4 Jun 2013
A = [1, 2; ...
3, 4];
B = kron(A, ones(3));
3 Comments
Voss
on 23 Apr 2025
Wesley
on 23 Apr 2025
@KONSTANTINOS VOSKAKISThat works even better for my application considering I just learned that the Kronecker product form matlab only works for 2D tensor rather than the 4D I work with!!!
More Answers (1)
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,[])
0 Comments
See Also
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!