How can I plot a string function?
1 次查看(过去 30 天)
显示 更早的评论
How can I plot a string function?
回答(1 个)
OCDER
2018-6-18
Is this the "string function" ?
StrFunc = 'x.^2+2*b+c';
%Converting to a function handle
Letters = unique(regexp(StrFunc, '[a-zA-Z]+', 'match')); %Extract the letters
VarPat = ['@(' sprintf('%s,', Letters{1:end-1}) Letters{end} ')']; %'@(a,b,x)'
Func = str2func([VarPat StrFunc]); % @(b, c, x) x.^2+2*b+c
x = 1:10;
b = 3;
c = 5;
plot(x, Func(b, c, x));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!