MATLAB: Adding variable values into legend

legendmultiple legendsplots

Hello, i am looping over different valuesthat effect the plot and i can get a legend that shows how these values relate to the lines shown in the plot. However i would also like to add another legend or something similar that will show some parameters that are manually set in the program.
ie: If gravity would effect the shape of my plot and i set gravity to 10 i would like to be able to have it show on the firgure that "10" was the value of gravity used for run of the plot
thanks

Best Answer

There are several ways to do that.
One is:
figure
plot((1:100), rand(1, 100).*sin(1:100))
gravity = 10;
gravstr = sprintf('Gravitational Acceleration is %.1f today',gravity);
legend(gravstr)
Experiment to get the result you want.