How do I find a variable number of functions?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
the cyclist
2014-10-15
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.
采纳的回答
Star Strider
2014-10-15
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Preferences 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!