MATLAB: How do i replace part of Symbolic Matrix

Symbolic Math Toolboxsymbolic matrix

If I have Matrix
delta = sym('R%d%d',[3,3])
[ R11, R12, R13]
[ R21, R22, R23]
[ R31, R32, R33]
If i want to replace R11 R22 and R33 with [1 2 3] i tried
subs(delta,[R11 R22 R33],[1 2 3])
This doesnt replace anything althought for 1d array it works
delta = sym('R%d',[1,3])
subs(delta,[R1 R2 R3],[1 2 3])
ans =
[ 1, 2, 3]

Best Answer

Based on the information in the second comment, I know what's going on. By the time MATLAB reaches the SUBS call, the variables R11, R22, and R33 are no longer symbolic and as such are no longer valid for use in the second input argument. One solution is to explicitly create symbolic variables inside the SUBS call:
subs(delta,{sym('R11') sym('R22') sym('R33')},{R11 R22 R33})
Another is to avoid overwriting the symbolic variables R11, R22, and R33 in the first place.
clear
syms R11 R22 R33 R1 R2 R3 R4 R5 R11 R12 R13 R21 R23 R31 R32
R1 =9;R2=4; R3=6;R4=3;R5=6;
R11D = R1+R2;
R22D = R1+R2+R3;
R33D = R3+R4+R5;
R21 = R1 + R2; R12 =R21;
R13 = 0; R31 =R13;
R23= R3; R32 =R23;
signsMat = [1 -1 -1;
-1 1 -1;
-1 -1 1];
delta = sym('R%d%d',[3,3]).*signsMat;
subs(delta,{R11 R22 R33},{R11D R22D R33D})
You'd want to do the same with the off-diagonal elements if you later wanted to substitute them into delta.