Converts a string into a function to plot
Afficher commentaires plus anciens
So I have mathematic functions like sin(x), cos(x) etc. in a string format that I want to convert into a function so I would be able to plot it.
equ='sin(x)';
f= @(x) equ;
plot(x,f)
error message:
Error using plot
Invalid data argument.
2 commentaires
"So I have mathematic functions like sin(x), cos(x) etc. in a string format that I want to convert into a function..."
Your example contains no strings or character arrays at all:
equ=sin(x);
f= @(x) equ;
This makes your question difficult to interpret. Do you actually have a character vector? E.g.:
str = 'sin';
Please show the actual definition of your input data.
iseinas
le 4 Sep 2020
Réponse acceptée
Plus de réponses (1)
KSSV
le 4 Sep 2020
equ=sin(x);
f= @(x) equ;
x = linspace(0,2*pi) ;
plot(x,f(x))
Catégories
En savoir plus sur Title dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

