Main Content

Create Arrays with repmat

The MATLAB® command repmat is used to replicate and tile arrays. It works on the built-in objects of MATLAB, namely double, char, as well as the generalized container objects cell and struct. The identical functionality is provided for replicating and tiling uncertain elements (ureal, ultidyn, etc.) and umat objects.

You can create an uncertain real parameter, and replicate it in a 2-by-3 uncertain matrix. Compare to generating the same uncertain matrix through multiplication.

a = ureal('a',5); 
Amat = repmat(a,[2 3]) 
UMAT: 2 Rows, 3 Columns 
  a: real, nominal = 5, variability = [-1  1], 1 occurrence 
Amat2 = a*ones(2,3); 
simplify(Amat-Amat2) 
ans = 
     0     0     0 
     0     0     0 

Create a [4-by-1] umat array by stacking four 1-by-3 umat objects with the stack command. Use repmat to tile this 1-by-3-by-4-by-1 umat, into a 2-by-3-by-8-by-5 umat.

a = ureal('a',4); 
b = ureal('b',2); 
M = stack(1,[a b 1],[-a -b 4+a],[4 5 6],[a 0 0]); 
size(M) 
ans = 
     1     3     4 
Mtiled = repmat(M,[2 1 2 5]) 
UMAT: 2 Rows, 3 Columns [array, 8 x 5] 
  a: real, nominal = 4, variability = [-1  1], 1 occurrence 
  b: real, nominal = 2, variability = [-1  1], 1 occurrence 
Verify the equality of M and a few certain tiles of Mtiled. 
d1 = simplify(M-Mtiled(2,:,5:8,3)); 
d2 = simplify(M-Mtiled(1,:,1:4,2)); 
d3 = simplify(M-Mtiled(2,:,1:4,5)); 
[max(abs(d1(:))) max(abs(d2(:))) max(abs(d3(:)))] 
ans = 
     0     0     0 

Note that repmat never increases the complexity of the representation of an uncertain object. The number of occurrences of each uncertain element remains the same, regardless of the extent of the replication and tiling.