I know many a question like this has been asked before, but the cases that I've seen are more complicated (i.e. I don't understand them) and the answers seem to pertain only to the specific cases.
My case is very simple (and thus broadly applicable), taken from MATLAB's very own help page:
syms x
f(x) = [x x^2; x^3 x^4];
f(2)
The output is supposed to be as follows:
ans =
[ 2, 4]
[ 8, 16]
But instead I get this error message. How come? And how do I fix it? Thanks.
If the input expression contains a symbolic variable, use the VPA
function instead.
Error in ==> sym.sym>sym.double at 936
Xstr = mupadmex('symobj::double', S.s, 0);
Error in ==> sym.sym>privformatscalar at 2678
x = double(x);
Error in ==> sym.sym>privformat at 2663
s = privformatscalar(x);
Error in ==> sym.sym>sym.subsasgn at 1433
[inds{k},refs{k}] = privformat(inds{k});
Chances are you have an older version of MATLAB (this code doesn't work for me on 2011b either). This should be equivalent:
syms x
f = [x x^2; x^3 x^4];
subs(f,2);