how to add numerical results to legend in matlab plot?
22 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm a beginner of matlab ...
I would like to add variance value below the mean value in the legend in my plot,
I tried the following codes, but it only displays the mean value, it doesn't display the variance value... ==
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194239/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194240/image.png)
How can I add variance value to it?
Thanks a lot :)
0 件のコメント
回答 (2 件)
Star Strider
2018 年 8 月 22 日
Example —
lgdstr = sprintf('\\mu_1 = %7.4f\n\\sigma_1 = %7.4f', mean_bl, std_dev_bl);
legend(lgdstr)
Change the format descriptors to get the result you want.
0 件のコメント
Arie Lerner
2018 年 8 月 22 日
OK, so what you need is make legend entry multi-line, right? One way to do it is introduce char 2xN char array, for example: ['first line';'secon line'] The problem is that your lines must be of the same length (otherwise it would not be an array) Here is an example: char({['mean=',num2str(mean(x))];['std=',num2str(std(1:10))]}) Here I used 2 lines with different length as input to a "char" function that converts it to an array. Char function also pads shorter lines with white spaces at their end. Curly braces mean I put the lines in cell array - cells allow combining different types of variables in same cell array (and different lengths of strings, obviously)
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!