How to add calculated parameters in to plot title

Hi,
I have below example plot, and I want to add more calculated parameters, but it give error.
x_variable=1:1:10;
y_variable=0.1:0.1:1;
mean_ab=mean(x_variable);
max_ab=max(x_variable);
std_ab=std(x_variable);
plot(x_variable,y_variable,'b--o')
title('x_variable:', mean_ab, max_ab, std_ab)
error is below:
Index exceeds matrix dimensions.
Error in titleplot (line 15)
title('x_variable:', mean_ab, max_ab, std_ab)

 採用された回答

Star Strider
Star Strider 2019 年 4 月 4 日

1 投票

Try this:
title(sprintf('x\\_variable: \\mu = %.2f, max = %.2f, \\sigma = %.2f', mean_ab, max_ab, std_ab))
Experiment to get the result you want.

4 件のコメント

Mekala balaji
Mekala balaji 2019 年 4 月 5 日
If I want to print variable name, max, mean in one line and std_ab in another line
title(sprintf('x\\_variable: \\mu = %.2f, max = %.2f, \\sigma = %.2f', mean_ab, max_ab, std_ab))
I do this like but it only print second line.
title(sprintf('x\\_variable: \\mu = %.2f', max = %.2f, mean_ab, max_ab))
title(sprintf(\\sigma = %.2f', std_ab))
Star Strider
Star Strider 2019 年 4 月 5 日
No need for two title calls (that likely would not do what you want anyway). Just insert a carriage return-linefeed (\n):
title(sprintf('x\\_variable: \\mu = %.2f, max = %.2f\n\\sigma = %.2f', mean_ab, max_ab, std_ab))
That should do what you want (and is another advantage of using sprintf here).
Mekala balaji
Mekala balaji 2019 年 4 月 5 日
Thanks,
Star Strider
Star Strider 2019 年 4 月 5 日
As always, my pleasure.

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by