MATLAB: Operating on syms class matrices.

classSymbolic Math Toolboxsyms

My algorithm returns matrices in the class "sym", of a similar form to the following matrix.
matrix =
[ a^2 + b*c, a*b + b*d]
[ a*c + c*d, d^2 + b*c]
I wish to switch the operators in this matrix. Such that, the '*' become '+' and vice versa. I then wish to use subs,
subs(mtx,[a b c d],[1 2 3 4])
in order to solve the matrix. Is there anyway to do this.
I can switch '*' for '+' and vice versa if I convert the matrices elements to char strings and simply search and replace, however this leaves solving the matrix for specific values of a,b,c and d problematic.
Any help would be greatly appreciated.
Regards
Ross

Best Answer

variant
p1 = regexprep(char(A),'+','_')
p2 = regexprep(p1,'*','+')
out = sym(regexprep(p2,'_','*'))