This issue is relative of converting decimals into fractions inside fprintf. I've tried using "sym", but the points still appear to be decimal.
x=0.25;
y=0.75;
fprintf('This is the Optimal Solution: [%f, %f]\n', sym(x), sym(y))
It will be a great help if anyone figure out the way to do this. Thank You.

 Respuesta aceptada

Star Strider
Star Strider el 20 de Mzo. de 2022

0 votos

Try using the rats function —
x=0.25;
y=0.75;
strlen = 3;
fprintf('This is the Optimal Solution: [%s, %s]\n', rats(x,strlen), rats(y,strlen))
This is the Optimal Solution: [ 1/4, 3/4]
.

2 comentarios

Charles Thomas
Charles Thomas el 20 de Mzo. de 2022
I really appreciate that! Thank you very much.
Star Strider
Star Strider el 20 de Mzo. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 20 de Mzo. de 2022

Comentada:

el 20 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by