Using the text command, how can I display a string genrated from sprintf and a string in one line?
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
I want to display the p value of a ttest on a graph that I have constructed. The label has to be in the format "p = XXXX" where XXXX is the p value. I used the ttest2 command to calculate the p value which I saved under the variable p_num. The command I am currently using is:
text(mean(xlim),max(ylim),['p =',p_num])
However this is not working. How can I get this to be displayed in the proper format on the graph?
1 Kommentar
Stephen23
am 17 Feb. 2015
What does "this is not working" actually mean? Do you get any text at all? Does it display the wrong text? Did it blow up your computer? We do try to read minds, but your explanation is better.
Antworten (1)
James Tursa
am 16 Feb. 2015
Bearbeitet: James Tursa
am 16 Feb. 2015
text(mean(xlim),max(ylim),sprintf('p = %4d',p_num))
If you need the leading 0's printed then
text(mean(xlim),max(ylim),sprintf('p = %04d',p_num))
4 Kommentare
S
am 16 Feb. 2015
James Tursa
am 17 Feb. 2015
What class variable is p_num? I was assuming it was numeric. Is it a string?
S
am 17 Feb. 2015
Stephen23
am 17 Feb. 2015
You don't need the intermediate string. Try this:
[h,pvl] = ttest2(Apm, Abm);
text(mean(xlim), max(ylim), sprintf('p = %.4f', pvl))
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!