String to a mathematical expression

how can i convert a String to a mathematical expression , that i can use in a function's body ?

2 commentaires

per isakson
per isakson le 22 Déc 2013
That depends. What does the String look like?
Elia
Elia le 23 Déc 2013
for example sin(x)-x^2

Connectez-vous pour commenter.

 Réponse acceptée

Matt J
Matt J le 22 Déc 2013

2 votes

If you display the string at the command line, you can then copy/paste it into the function's body.

2 commentaires

Elia
Elia le 22 Déc 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 le 22 Déc 2013
Modifié(e) : Matt J le 22 Déc 2013
If the string will always be a function of a known letter, e.g. 'x', you can do
theFunc = str2func(['@(x)' theString])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Question posée :

le 22 Déc 2013

Commenté :

le 23 Déc 2013

Community Treasure Hunt

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

Start Hunting!

Translated by