Create Arrays with usubs

Suppose Values is a struct array, with the following properties: the dimensions of Value match the array dimensions of M, as described in Create Arrays with usample; the field names of Values are some (or all) of the names of the uncertain elements of M; and the dimensions of the contents of the fields within Values match the sizes of the uncertain elements within M. Then usubs(M,Values) will substitute the uncertain elements in M with the contents found in the respective fields of Values.

You can create a 3-by-2 uncertain matrix using two uncertain real parameters.

a = ureal('a',4); 
b = ureal('b',2); 
M = [a b;b*b a/b;1-b 1+a*b]; 

Create a 5-by-1 struct array with field name a. Make its values random scalars. Create a 1-by-4 struct array with field name b.

Avalue = struct('a',num2cell(rand(5,1))); 
Bvalue = struct('b',num2cell(rand(1,4))); 

Substitute the uncertain real parameter a in M with the values in Avalue, yielding ma. Similarly substitute the uncertain real parameter b in M with the values in Avalue, yielding mb.

ma = usubs(M,Avalue) 
UMAT: 3 Rows, 2 Columns [array, 5 x 1] 
  b: real, nominal = 2, variability = [-1  1], 6 occurrences 
mb = usubs(M,Bvalue) 
UMAT: 3 Rows, 2 Columns [array, 1 x 4] 
  a: real, nominal = 4, variability = [-1  1], 2 occurrences 

Continue, substituting the uncertain real parameter b in ma with the values in Bvalue, yielding mab. Do the analogous operation for mb, yielding mba. Subtract, and note that the difference is 0, as expected.

mab = usubs(ma,Bvalue); 
mba = usubs(mb,Avalue); 
thediff = mab-mba; 
max(abs(thediff(:))) 
ans = 
  4.4409e-016 
Was this topic helpful?