How to get the string form of an anonymous function?
3 ビュー (過去 30 日間)
古いコメントを表示
I was thinking about creating a function, which automatically creates plot, data, etc. This function is supposed to be an aid for solving differential equations with numerical methods.
The function is:
function [x,yf,yg]=graphing(f,g,interval)
x = linspace(interval(1),interval(end),80);
yf = f(x);
yg = g(x);
plot(x,yf,'g',x,yg,'b');
tf = 'f(x)=';
tg = 'g(x)=';
legend(tf,tg);
end
And the command could be:
interval = [0 4];
f = @(x) exp(-0.5*x);
g =@(x) sin(2*x);
[x,yf,yg] = graphing(f,g,interval)
There is a way to get the string form of the functional notation for the anonymous function, so that it is possible having in legend the exact function form? It could help me for orientation, even if it is not necessary. Just as a matter of interest.
Thank you in advance.
採用された回答
Fangjun Jiang
2021 年 2 月 16 日
編集済み: Fangjun Jiang
2021 年 2 月 16 日
f = @(x) exp(-0.5*x);
>> func2str(f)
ans =
'@(x)exp(-0.5*x)'
Or, provide your string, use str2func()
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!