matlab - How to convert string to a function name? -


how go converting x = 'abs' abs z = abs(-5) = 5. or x = 'randfunc' 'randfunc' can input string relating function.

>> x  x =  abs  >> x(-5) subscript indices must either real positive integers or logicals. 

use str2func:

x = 'abs'; fh = str2func(x); fh(-5)               % prints 5 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -