How do I find a variable number of functions?
5 views (last 30 days)
Show older comments
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.
2 Comments
the cyclist
on 15 Oct 2014
I am not sure what you mean by "find" here. What is your input? What do you expect your output to be. State it in terms of MATLAB, not just a description. We only know what you tell us. Contrary to popular belief, we cannot read minds.
Accepted Answer
Star Strider
on 15 Oct 2014
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.
More Answers (0)
See Also
Categories
Find more on Symbolic Variables, Expressions, Functions, and Preferences in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!