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!