How do I insert a variable value in legend of a plot?

220 vues (au cours des 30 derniers jours)
Arjun Siddharth
Arjun Siddharth le 6 Sep 2021
I have a varible p, with a value -2.2. How do I insert this value in the legend function, for a plot?
eg.- legend('Value 1=p'); % I wish to have the numeric value of p (2.2) in place of 'p'.

Réponse acceptée

Murugan C
Murugan C le 6 Sep 2021
use below code
value_x = 2.2;
value_y = 2.5;
legend(sprintf('Value-X = %g',value_x),sprintf('Value-Y = %g',value_y))

Plus de réponses (1)

DGM
DGM le 6 Sep 2021

Community Treasure Hunt

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

Start Hunting!

Translated by