Variable plot title and legend
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello!
I am writing a code in which the user can input their own functions and minimum and maximum values. I'd like the title and legend to change according to the function input by the user, so instead of "Function 1" it could say sin(x) or whatever else the used chooses. I don't know how to do this. Any ideas? Help would be much appreciated.
0 comentarios
Respuestas (2)
Star Strider
el 6 de Dic. de 2019
The easiest way is to use the sprintf function inside the title and legend, respectively. It also allows straightforward inclusion of numerical and other string data. Remember to use double backslants (\\) if you want to include a backslant (for example if you wnat to use TeX or LaTeX strings) so they will be interpreted coorrectly and not as sprintf control characters.
0 comentarios
KALYAN ACHARJYA
el 6 de Dic. de 2019
Editada: KALYAN ACHARJYA
el 6 de Dic. de 2019
Other way apart from @Star's Answered: For variable data title plot, see this example:
xmin=input('please input your minimum value: ');
xmax=input('please input your maximum value: ');
data=xmin:0.01:xmax;
plot(data);
hold on;
title("Plot with xmin: " + xmin);
xmin=input('please input your minimum value: ');
xmax=input('please input your maximum value: ');
data=xmin:0.01:xmax;
plot(data);
title("Plot with xmin: " + xmin);
0 comentarios
Ver también
Categorías
Más información sobre Legend en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!