How to bold, italics sentence using fprintf in matlab?

 Risposta accettata

There is no mechanism for that, just as there is no mechanism for color or underlining or blinking.
fprintf() is for transferring characters, and characters do not have inherent attributes or font properties.
Having said that: some output destinations interpret the characters they receive, and do so in such a way that character or font information can be attached.
The above are for output to the command window. If you happen to be outputting to a terminal emulator (e.g., if you are running matlab -nodesktop) then you may be able to take advantage of the ANSI sequences for text attributes: http://en.wikipedia.org/wiki/ANSI_escape_code#graphics

Più risposte (1)

You can print bold only (not italics) using fprinf as shown below.
fprintf('Hello <strong> bold </strong> world.\n')
>> Hello bold world.

8 Commenti

fprintf(' <strong> Hello world.</strong> \n')
Hello world.
whoa! Where is this documented?
Any why does it work on the command line but not a UI figure??
When you use uifigure() you can use uihtml() https://www.mathworks.com/help/matlab/ref/uihtml.html
However, for "traditional figures", only uicontrol style 'radio' and 'push' and 'dropbox' and 'listbox', and uitable supported HTML -- in particular not uicontrol style 'edit' or uicontrol 'text'
It worked very well. Thanks
Works nicely in the MATLAB console window (R2023b)
Unfortunatly when using publish() to create a pdf or html document the same example apears as 'Hello <strong> bold </strong> world.' in the document.
I'm having the same issue when using publish() to create the PDF. Has anyone found the solution?

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by