Clear Filters
Clear Filters

displaying text before answer

99 views (last 30 days)
Birce Irmak
Birce Irmak on 10 Nov 2019
Answered: Sarvesh Kale on 9 Mar 2023
So I made a function on matlab but i want matlab to display 'the answer is' text and then the answer . How am I suppose to do that? I think I have to use disp code but I couldn't figure how.

Answers (2)

Walter Roberson
Walter Roberson on 10 Nov 2019
Edited: Walter Roberson on 10 Nov 2019
Use fprintf() using a format that does not end in \n if you want to display something without going to the next line after.

Sarvesh Kale
Sarvesh Kale on 9 Mar 2023
refer to the following code
x = 3.14 ;
fprintf("The value of pi is %f \n",x); % this will print the answer in your required format
The value of pi is 3.140000
I hope this helps

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!