Variable plot title and legend
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Star Strider
am 6 Dez. 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 Kommentare
KALYAN ACHARJYA
am 6 Dez. 2019
Bearbeitet: KALYAN ACHARJYA
am 6 Dez. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!