MATLAB: How to find a variable number of functions

a variable number of functions

Hello everyone How do I find a variable number of functions? For example, f = x1 + 2 * x2 two variables and variables [x1 x2] 2 variables f = 2 * x + y ^ 2 + u ^ 3 three variables and variables [x y u] 3 variables Thank you very much, everybody.

Best Answer

Use the symvar function, then the length or size functions.
Using symvar:
f1 = 'x1 + 2 * x2'
f2 = '2 * x + y ^ 2 + u ^ 3'
s1 = symvar(f1)
s2 = symvar(f2)
produces:
s1 =
'x1'
'x2'
s2 =
'u'
'x'
'y'
That is as good as it gets, though. You have to cast the expressions as strings, and they cannot be function handles. I cannot find any other functions that would do what you want.