User-defined Functions Applied throughout a Script
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am attempting to write a Matlab script that uses a user-input (hence general) function, f(x), throughout the script. I thought of using he following:
f = @(x) input('Enter f(x): ')
but then when my (iterative) While loop is executed which contains (f(x)), the prompt pops up after every cycle.
I'd be grateful for any help!
0 个评论
采纳的回答
Walter Roberson
2011-8-7
If you have a sufficiently new version of MATLAB,
f = str2func(['@(x)' input('Enter f(x):','s')]);
If your version of MATLAB is a bit older, you need to either inline() or eval() instead of using str2func()
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Handles 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!