Can I acess value of variable in legend of plot

조회 수: 35 (최근 30일)
venkat siddhartha rama
venkat siddhartha rama 2019년 7월 22일
댓글: Charaf-ed-dine EL FATTAHI 2022년 2월 15일
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