Can I acess value of variable in legend of plot

35 次查看(过去 30 天)
Hi, I have a plot for which I need to have the integrated values next to each legend. I mean, Can I use %0.2f which is used in fprintf statement to get the value of the variable used. Below is the code line of the legend, Hopefully I have explained it well enough..
% Code Line Begins here%
legend('Only Solar Generation[Integrated = %0.2f KW]','Only Wind Generation[Integrated = %0.2f KW]' ,'Load of community[Integrated = %0.2f KW]','Combined wind and solar power produced[Integrated = %0.2f KW]', 'Excess Energy Produced[Integrated = %0.2f KW]','Defecit Energy[Integrated = %0.2f KW]', Integrated_Just_solar_Farm_generation,Integrated_hourly_wind_power1,Integrated_Community_Hourly_load_demand,Integrated_comined_wind_and_solar_power,Integrated_Excess_energy_produced,Integrated_Defecit_Energy );
%Code line Ends here%

采纳的回答

Image Analyst
Image Analyst 2019-7-23
I would make up each legend using sprintf, then call legend
legend1 = sprintf('Only Solar Generation[Integrated = %0.2f KW]', num1);
legend2 = sprintf('Whatever...%f', num2);
legend3 = sprintf('Whatever...%.1f', num3);
legend(legend1, legend2, legend3);
It's a lot simpler this way.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by