Adding Second Line to Text Box in Plot

조회 수: 67 (최근 30일)
Matthew
Matthew 2017년 9월 26일
댓글: Star Strider 2017년 9월 26일
Hi folks. I have another formatting question. I want to place a text box in a 3D plot. I have the following code where I calculate ResTime and then create a character string with it. I then issue the text command and I want the text box to have two lines, reading as such:
Particle residence
time=0.10s
Here's my code (minus the rest of the plotting commands). It won't work though. It'll create the first line of the text box, but not the second.
ResTime=L/U_f(1,3); %equals 0.10
str_textbox=sprintf('time=%4.2f s',ResTime);
text(.01,.01,.01,sprintf('Particle residence \n', str_textbox));
Thanks in advance,
M Ridzon

채택된 답변

Star Strider
Star Strider 2017년 9월 26일
Combine both lines in one sprintf call to print a two-line text:
ResTime = 0.10;
figure(1)
plot(rand(1,5)-0.5, rand(1, 5)-0.5, 'pg')
text(.01,.01,.01,sprintf('Particle residence \ntime=%4.2f s',ResTime));
If I understand what you want to do, this should work.
  댓글 수: 2
Matthew
Matthew 2017년 9월 26일
Beautiful! Quick-n-simple response. Easy fix. That's what I love about this forum! Thanks again!
Star Strider
Star Strider 2017년 9월 26일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by