Replicate matrix elements without for loop

I am trying to take the matrix
base =[1 2; 3 4]
and replicate the elements to give
expn = [ 1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4]
without using for loops. I would like to use repmat but not sure how to do that elementwise.

1 Comment

Got it!
N = 2; base = [1 2; 3 4]
expn = kron(base,ones(N))

Sign in to comment.

 Accepted Answer

base =[1 2; 3 4];
repelem(base,2,2)
ans = 4×4
1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4

More Answers (0)

Categories

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!