Hello, Can you help me to change colour and fontsize using sprintf ?

21 Ansichten (letzte 30 Tage)
made sutawan
made sutawan am 8 Apr. 2017
Kommentiert: Matin Salehi am 9 Mai 2019
Hello, Can you help me to change colour and fontsize using sprintf ? This is my code . sprintf('Kualitas : Sangat Bagus');
  1 Kommentar
Stephen23
Stephen23 am 8 Apr. 2017
@made sutawan: This is not possible: character strings (such as the output of sprintf are simlple arrays of character codes, and do not contain formatting information.
If you want formatted text then you can use a GUI.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jan
Jan am 8 Apr. 2017
As Stephen has explained already: sprintf creates a string, which is a character vector and doe not contain any information about the color or the font.
To influence the font and color, you have to displays this string anywhere, e.g. in the command window or in a GUI. In the first case there are only limited possibilities, see e.g. https://www.mathworks.com/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-the-command-window FEX: cprintf>. If you write to an ASNI terminal, see FEX: txprintf. For GUIs you can use LaTeX formatting, see:
docsearch latex
  1 Kommentar
Matin Salehi
Matin Salehi am 9 Mai 2019
do you know how can i disp a word, like
disp('hello')
but i want to chang its fontsize and color. how cam=n i do that with disp command

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 8 Apr. 2017
Bearbeitet: Image Analyst am 8 Apr. 2017
Once you create the string with sprintf() then you can send it to controls like an xlabel, ylabel, title, or text along with options to control the font, size, color, etc. For example
text(x, y, yourString, 'FontSize', 20, 'Color', 'r', 'FontWeight', 'bold');

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by