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
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.
Volkan
Volkan 2014-10-15
编辑:the cyclist 2014-10-15
I'm looking for a command as I mentioned in the following example.
a=????(x1 + 2 * x2)
b=?????(x1 + 2 * x2)
a=2
b=[x1 x2]
or
c=????(2 * x + y ^ 2 + u ^ 3)
d=?????(2 * x + y ^ 2 + u ^ 3)
c=3
d=[x y u]

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2014-10-15
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.

更多回答(0 个)

类别

Help CenterFile 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!

Translated by