How can I plot a string function?

1 回表示 (過去 30 日間)
Adebayo Bamidele Olanrewaju
Adebayo Bamidele Olanrewaju 2018 年 6 月 18 日
回答済み: OCDER 2018 年 6 月 18 日
How can I plot a string function?
  1 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 6 月 18 日
What is a string function?

サインインしてコメントする。

回答 (1 件)

OCDER
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));

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by