String to a mathematical expression

2 Ansichten (letzte 30 Tage)
Elia
Elia am 22 Dez. 2013
Kommentiert: Elia am 23 Dez. 2013
how can i convert a String to a mathematical expression , that i can use in a function's body ?
  2 Kommentare
per isakson
per isakson am 22 Dez. 2013
That depends. What does the String look like?
Elia
Elia am 23 Dez. 2013
for example sin(x)-x^2

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 22 Dez. 2013
If you display the string at the command line, you can then copy/paste it into the function's body.
  2 Kommentare
Elia
Elia am 22 Dez. 2013
i want to get the string from an edit text feld in a gui . it will be a function's body that i want to plot it .
Matt J
Matt J am 22 Dez. 2013
Bearbeitet: Matt J am 22 Dez. 2013
If the string will always be a function of a known letter, e.g. 'x', you can do
theFunc = str2func(['@(x)' theString])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by