フィルターのクリア

how to write in legend function ?

1 回表示 (過去 30 日間)
tomer polsky
tomer polsky 2020 年 11 月 15 日
コメント済み: tomer polsky 2020 年 11 月 16 日
I want to write the function in the legend ,automtaic for exmaple :
n=0:10e3;
f=(log2(n)).^2;
c_gn=10*((log2(n)).^2);
plot(n,f,n,c_gn);
legend('(log2(n)).^2','10*((log2(n)).^2');
I want that in the leged to change aoutomtacli every time I change f or c_gn and not the expression of the vaule manually in the legend . how to do it ?

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 15 日
n = 0:10e3;
f_fun = @(n) (log2(n)).^2;
c_gn_fun = @(n) 10*((log2(n)).^2);
f_legend = regexprep(func2str(f_fun), '^.*?)', '');
c_gn_legend = regexprep(func2str(c_gn_fun), '^.*?)', '');
f = f_fun(n);
c_gn = c_gn_fun(n);
plot(n, f, n, c_gn);
legend({f_legend, c_gn_legend});
  1 件のコメント
tomer polsky
tomer polsky 2020 年 11 月 16 日
thank you very much !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by