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
Post a Comment