String to a mathematical expression

2 visualizzazioni (ultimi 30 giorni)
Elia
Elia il 22 Dic 2013
Commentato: Elia il 23 Dic 2013
how can i convert a String to a mathematical expression , that i can use in a function's body ?
  2 Commenti
per isakson
per isakson il 22 Dic 2013
That depends. What does the String look like?
Elia
Elia il 23 Dic 2013
for example sin(x)-x^2

Accedi per commentare.

Risposta accettata

Matt J
Matt J il 22 Dic 2013
If you display the string at the command line, you can then copy/paste it into the function's body.
  2 Commenti
Elia
Elia il 22 Dic 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 il 22 Dic 2013
Modificato: Matt J il 22 Dic 2013
If the string will always be a function of a known letter, e.g. 'x', you can do
theFunc = str2func(['@(x)' theString])

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by