String to a mathematical expression

2 visualizaciones (últimos 30 días)
Elia
Elia el 22 de Dic. de 2013
Comentada: Elia el 23 de Dic. de 2013
how can i convert a String to a mathematical expression , that i can use in a function's body ?
  2 comentarios
per isakson
per isakson el 22 de Dic. de 2013
That depends. What does the String look like?
Elia
Elia el 23 de Dic. de 2013
for example sin(x)-x^2

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by