Hi, can any one please help me figuring out how can I write this title?
For the value of A, t, and phi I want to use the notation %d, %0.3f, and %0.2f
Thank you!!

 採用された回答

Walter Roberson
Walter Roberson 2023 年 3 月 7 日

0 投票

Hint:
fprintf('%d %0.3f %0.2f', randi(10), randn, randn)
5 1.085 0.37

7 件のコメント

Ashfaq Ahmed
Ashfaq Ahmed 2023 年 3 月 7 日
Hi! I want to write the entire thing actually.
Walter Roberson
Walter Roberson 2023 年 3 月 7 日
You want written as the title ? In fraction form and π symbol and everything? If so then is + -2.50 acceptable or does the negative have to be detected so it shows as - 2.50 complete with space between the negative sign and the number ?
Ashfaq Ahmed
Ashfaq Ahmed 2023 年 3 月 7 日
Hi @Walter Roberson, yes, this is exactly what I want.
+- is acceptable
Walter Roberson
Walter Roberson 2023 年 3 月 7 日
Okay, for this you will need to use sprintf or compose and you will need to have the resulting string be in latex format. You would then title() the string with 'interpreter', 'latex'
There is a trick here, that latex needs a lot of \ characters but sprintf() and compose() use \ to signal as well. So in order to create a \ character to reach latex you need to use \\ in the format
S = sprintf('$%d \\sin(%.2f \\pi)$', 83, 19.24)
S = '$83 \sin(19.24 \pi)$'
title(S, 'interpreter', 'latex')
except that you will need to use more complicated latex to get the fraction; see latex \frac
Ashfaq Ahmed
Ashfaq Ahmed 2023 年 3 月 7 日
This is so cool! Shall I use the \frac command to write Sin(2*pi/365)?
Ashfaq Ahmed
Ashfaq Ahmed 2023 年 3 月 7 日
編集済み: Ashfaq Ahmed 2023 年 3 月 7 日
Got this!!
S = sprintf('$%0.2f + %0.2f \\sin( \\frac{%0.d \\pi}{365} + %0.2f)$', 10.05, 8.89, 2, -2.05)
S = '$10.05 + 8.89 \sin( \frac{2 \pi}{365} + -2.05)$'
title(S, 'interpreter', 'latex')
Walter Roberson
Walter Roberson 2023 年 3 月 7 日
that looks good

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by