Using a variable to help fill in the legend line on a plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a variable that is named in the first lines of my program. It changes each day. I need the variable to fill in a part of legend text.
The variable is below.
Volts="25";
The code for the legend is below.
legend('25V Open circuit 10 to 90% Rise Time');
I need to know how to make it replace only the 25 in the legend with the variable number in enter Volts="XX";
Thank you
0 Kommentare
Antworten (1)
DGM
am 7 Nov. 2021
Bearbeitet: DGM
am 7 Nov. 2021
You can use sprintf() to construct a bit of text from numeric variables or other string/char variables. Then you can use that in your legend or title as needed.
p = [1 2 3];
x = linspace(0,1,100);
for n = 1:numel(p)
y = x.^p(n);
subplot(1,numel(p),n)
plot(x,y)
legend(sprintf('y = x^%d',p(n)),'location','northwest')
end
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!
