필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Using the text command, how can I display a string genrated from sprintf and a string in one line?

조회 수: 1 (최근 30일)
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
Stephen23
Stephen23 2015년 2월 17일
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.

답변 (1개)

James Tursa
James Tursa 2015년 2월 16일
편집: James Tursa 2015년 2월 16일
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
S
S 2015년 2월 17일
Yes it is a string. Here is the full context of what I am doing. Apm and Abm are a set of values.
[h,pvl]= ttest2(Apm,Abm);
p_num = sprintf(['%.4f', pvl]);
text(mean(xlim),max(ylim),['p =',p_num])
Stephen23
Stephen23 2015년 2월 17일
You don't need the intermediate string. Try this:
[h,pvl] = ttest2(Apm, Abm);
text(mean(xlim), max(ylim), sprintf('p = %.4f', pvl))

이 질문은 마감되었습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by