필터 지우기
필터 지우기

How to take value from function and put it into disp script?

조회 수: 1 (최근 30일)
Anne Nguyen
Anne Nguyen 2019년 9월 28일
댓글: Star Strider 2019년 9월 28일
My task is to "display the words: 'The ball hits the ground at a distance of X meters', where X is the hitDistance from the function throwBallFunc." (I have written the throwBallFunc).
So far, I have disp( ' The ball hits the ground at a distance of %d meters '); which is not working. How do I write it so that I can get the value of X aka hitDistance from the function throwBallFunc that I created? Thank you!

채택된 답변

Star Strider
Star Strider 2019년 9월 28일
Use:
sprintf( ' The ball hits the ground at a distance of %d meters ',X)
or:
fprintf( ' The ball hits the ground at a distance of %d meters ', X)
instead, depending on what you want to do.
  댓글 수: 2
Anne Nguyen
Anne Nguyen 2019년 9월 28일
I have to use the disp function. Any way I can do it with that?
Star Strider
Star Strider 2019년 9월 28일
Yopu didn’t say that.
Try this:
disp([' The ball hits the ground at a distance of ' num2str(X) ' meters '])
That worked when I tested it. It uses the MATLAB concatenation operator [] to create one character array from three character arrays.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by