Values in function handle (this worked for inline...)
이전 댓글 표시
I want to create sets of random linear functions: m*x+b for many different m values and b values. I used to do something like this:
s = sprintf('%d*x+%d',randi(10), randi(3))
f = inline(s)
and I'd end up with an f nicely defined in terms of my random variables (f = 8x+2). Then I can plot and/or evaluate this function for any x.
How do I do something similar with function handles? I have tried doing:
F = @(x) s;
but it appears that it substitutes s in and doesn't understand x is an argument (so F(1) = 8*x+2, not 8*1+2).
I obviously do NOT want to create a brand new function file (which is why I want inline functions in the first place).
Anyone have any ideas?
Regards,
Dr. Dostert
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!