Printing equations stored in a cell to plot titles?

1 回表示 (過去 30 日間)
Braden Kerr
Braden Kerr 2020 年 11 月 26 日
コメント済み: Ameer Hamza 2020 年 11 月 26 日
Hello,
Currently i have multiple equations stored a cell array and would like to print them as the titles to various plots. Since I am calling the cells in a loop I would like to do soemthing like this but I dont think sprintf is the correct way to apprach it.
q_array = {@(x)ones(size(x)); @(x) abs(x); @(x) x.^2; @(x) (1/3)+(2/3)*x.^2};
for k =1:4
%Code that generates the plot for each loop
formatspec = 'Exact vs Scheme Plots for q({\nu}) = %s';
sgtitle(sprintf(formatspec, q_array{k}));
end
Thank you

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 26 日
編集済み: Ameer Hamza 2020 年 11 月 26 日
Although you can use func2str() to convert the function handle to char array
sgtitle(sprintf(formatspec, func2str(q_array{k})));
but a more flexible solution is to create a seperate array for titles
q_array = {@(x)ones(size(x)); @(x) abs(x); @(x) x.^2; @(x) (1/3)+(2/3)*x.^2};
q_titles = {'ones(size(x))'; 'abs(x)'; 'x^2'; '(1/3)+(2/3)*x^2'};
for k =1:4
%Code that generates the plot for each loop
figure;
formatspec = 'Exact vs Scheme Plots for q({\\nu}) = %s';
sgtitle(sprintf(formatspec, q_titles{k}));
end
It gives more control over what appears in the title.
  2 件のコメント
Braden Kerr
Braden Kerr 2020 年 11 月 26 日
Thank you
Ameer Hamza
Ameer Hamza 2020 年 11 月 26 日
I am glad to be of help!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by