How do I get the text command to display my character string in one line on a plot?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aaron Trego
am 2 Mär. 2023
Beantwortet: Les Beckham
am 2 Mär. 2023
I am plotting collected data against a function of the theoretical values, and calculated the correlation coefficient for the data sets. When I display it on my plot, it shows in 2 lines instead of 1.
This is what I am currently doing:
text(260,40,{'r =' r}) %where r is the correlation coefficient calculated prior in my code.
Here is how it is plotting:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1312500/image.png)
Thanks in advance!
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 2 Mär. 2023
r = pi; % arbitrary value for testing
{'r =' r} % Matlab will put each element of a cell array on a different line in text, title, etc.
figure
grid on
xlim([0 400]) % specify axis limits so the text will show up
ylim([0 80])
cv = sprintf('r = %f', r)
text(260, 40, cv) % use a single char vector instead of a cell array
figure
grid on
xlim([0 400]) % specify axis limits so the text will show up
ylim([0 80])
str = "r = " + r % or you can use a string
text(260, 40, str)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations 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!