matlab says the inline function will be removed in future release how should i execute a string function like '2*x.^2+5'
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
omid
el 20 de Jun. de 2017
Comentada: Alfonso Rodriguez
el 29 de Jun. de 2021
function
1 comentario
Stephen23
el 20 de Jun. de 2017
How about using anonymous functions, just like the documentation recommends?
Respuesta aceptada
Star Strider
el 20 de Jun. de 2017
Your function becomes:
fcn = @(x) 2*x.^2+5;
the call it as you would any other function:
y = fcn(x);
str = '2*x.^2+5';
fun = str2func(['@(x) ',str]);
y = fun(x);
This creates the anonymous function from the string, and returns a function handle.
6 comentarios
Steven Lord
el 21 de Jun. de 2017
Use the symvar function to identify the variable(s) and use the char vector it returns in defining the char vector you pass into str2func.
Alfonso Rodriguez
el 29 de Jun. de 2021
Thanks for these comments. They are very useful for computational math.
Más respuestas (1)
Ver también
Categorías
Más información sobre Function Creation 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!