recognize function from string

6 ビュー (過去 30 日間)
Zak Kankin
Zak Kankin 2017 年 3 月 25 日
コメント済み: Star Strider 2017 年 3 月 25 日
Is there a way in Matlab to recognize the variables and parametest of function from sting. For example I have a string: "a1*x+a2*x^2+y", and necessary to get a function where a1,a2 - constants and x, y - variables.

採用された回答

Star Strider
Star Strider 2017 年 3 月 25 日
Not that I am aware of.
The closest you can get to what you want to do (in this example of a polynomial) is the Symbolic Math Toolbox coeffs function, and even then you have tell it what the variables are:
syms a1 a2 x y
z = a1*x+a2*x^2+y;
[coefficients,variables] = coeffs(z, [x y])
coefficients =
[ a2, a1, 1]
variables =
[ x^2, x, y]
  2 件のコメント
Zak Kankin
Zak Kankin 2017 年 3 月 25 日
編集済み: Zak Kankin 2017 年 3 月 25 日
Thanks! It works great for string in exactly if I want! '[coefficients,variables] = coeffs('a1*x+a2*x^2+y', [x y])'
coefficients = [ a2, a1, 1] variables = [ x^2, x, y]
Star Strider
Star Strider 2017 年 3 月 25 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by