Could I use a function of x as input like this ( fun = input(' Function of x = ');) and then when I run the program insert a function of x ?
2 次查看(过去 30 天)
显示 更早的评论
Could you give me an example when the input is a function of x rather than a numerical term?
0 个评论
采纳的回答
James Tursa
2016-7-27
E.g., input your function as a MATLAB syntactically correct string, then use the str2func function to form a function handle. E.g.,
>> s = input(' Function of x = ','s')
Function of x = 2*x+1
s =
2*x+1
>> fun = str2func(['@(x)' s])
fun =
@(x)2*x+1
>> fun(1)
ans =
3
>> fun(2)
ans =
5
>> fun(3)
ans =
7
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!