Replicate matrix elements without for loop

1 vue (au cours des 30 derniers jours)
Howard Wilton
Howard Wilton le 22 Nov 2022
Commenté : Howard Wilton le 22 Nov 2022
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 commentaire
Howard Wilton
Howard Wilton le 22 Nov 2022
Got it!
N = 2; base = [1 2; 3 4]
expn = kron(base,ones(N))

Connectez-vous pour commenter.

Réponse acceptée

David Hill
David Hill le 22 Nov 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by