MATLAB: How can i substitute elements of a symbolic matrix with arrays of numbers

substitutionsymbolic matrix

Hi,
i have a symbolic matrix
A(2*3) = [a_1 a_2 a_3; a_4 a_5 a_6];
also i have 20*1 arrays of numbers. such as
b_1(20,1),b_2(20,1),b_3(20,1),b_4(20,1),b_5(20,1).
i need to substitute elements of symbolic matrix with elements of array one at a time, lets say
a_1=b_1(1,1),a_2=b_2(1,1),a_3=b_3(1,1),a_4=b_4(1,1),a_5=b_5(1,1)
and keep substituting to the last elements of a_1=b_1(20,1), ….
can someone please give me a hint?
thank you in advance

Best Answer

arrayfun(@(K) subs(A, A, [b_1(K), b_2(K), b_3(K); b_4(K), b_5(K), b_6(K)]), 1:length(b_1), 'Uniform', 0)
Note that the substituting vector, [b_1(K), b_2(K), b_3(K); b_4(K), b_5(K), b_6(K)] must be the same shape as the vector of variables, A, for this to work.
An easier way to handle this would be
mat2cell( reshape([b_1, b_2, b_3, b_4, b_5, b_6], [], 3, 2), ones(1, length(b_1)), 3, 2 )
since really your A is not participating in the process.
Related Question