Plot title sprintf format pi

141 views (last 30 days)
How can I display on a plot's Title the input value pi with Greek character "π" or in English "pi". For example: prompt = 'What is the original value? '; x = input(prompt) I insert the value pi/2 So i want the plot title to be like: Output=π/2 I used the following code but it keeps giving me the value 0.707 instead of the π/2 or pi/2 i want.
str = sprintf('Output x=%d',x);
title(str);

Accepted Answer

Kirby Fears
Kirby Fears on 23 Dec 2015
Edited: Kirby Fears on 23 Dec 2015
x is a double-precision floating point number. It will be displayed as a decimal by default. You can control how the double is represented (like scientific notation), but there is no built-in ability to display a double in terms of pi multiples. You're specifically trying to represent x in terms of pi/n for the appropriate n value.
Use the '\pi' character to display the symbol for pi. Calculate the value n = pi/x to build the expression "x = pi/n" in the title.
str = sprintf('Output x=%s/%d','\pi',pi/x);
title(str);
  4 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!