¿How can I change letter colour?

18 ビュー (過去 30 日間)
Nerea  Amondarain
Nerea Amondarain 2015 年 9 月 15 日
コメント済み: Walter Roberson 2024 年 11 月 28 日
No puedo cambiar el color rojo de las letras después del texto del input o disp. Quiero ponerlos en morado en vez de en rojo que hago?

回答 (2 件)

Star Strider
Star Strider 2015 年 9 月 15 日
If you want to change the colour of text written to the Command Window, use the file identifier 2 with fprintf:
fprintf(2, 'This displays in red.\n')
to display text objects (like plot titles and axis labels) in red, see the documentation in Text Properties for 'Color'.
  3 件のコメント
Jean-Baptiste
Jean-Baptiste 2024 年 11 月 28 日
Example:
fprintf('This is something interesting','Color','r','\n');
This is something interesting
this is display "This is something interesting" in red.
Walter Roberson
Walter Roberson 2024 年 11 月 28 日
There is no interface in fprintf() or any other Mathworks supplied function that allows you to set the color of text using a 'Color' option.
What there is is a File Exchange contribution, https://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-command-window . Note that cprintf() can only handle one style at a time -- so for example if you wanted the \n to be (somehow) a different color than the 'This is something interesting' then you would need two cprintf() calls.

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


Hamoon
Hamoon 2015 年 9 月 15 日

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by