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.

 채택된 답변

Star Strider
Star Strider 2022년 3월 20일

0 개 추천

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

Charles Thomas
Charles Thomas 2022년 3월 20일
I really appreciate that! Thank you very much.
Star Strider
Star Strider 2022년 3월 20일
As always, my pleasure!

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

추가 답변 (0개)

제품

릴리스

R2021b

질문:

2022년 3월 20일

댓글:

2022년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by