30 Sept 2022

Change Matlab Command Window's Text Colour

收藏到CSDN网摘

Matlab has provided some coloured text features already. For instance, the default 'disp' or 'fprintf' will print text in balck colour, while 'warning' displays text in orange and 'error' displays text in red (yes, error also terminates your script). But someone may want more flexibilities over these default one. Fortunately, there are some work around available for this issue.





For easy tasks such as 'hyperlink':
disp('<a href="">my text</a>')
or
fprintf('<a href="">my text</a>')
ORANGE text without using 'warning' as it may be turned off by 'warning off':
fprintf('[\btest]\b\n');
another way of RED text without using 'error' to break the runs:
fprintf(2, 'test');
BOLD text:
fprintf('<strong>test</strong>\n');
not surprisingly, BOLD + RED:
fprintf(2,'<strong>test</strong>\n');
and BOLD + ORANGE(colour must be outside the bold syntax):
fprintf('[\b<strong>test</strong>]\b\n');
The above samples of styles might be sufficient than you need. However, if you do need more styles please have a look to the 'cprintf' functions. The detailed of the implementation can be found HERE.

No comments :

Post a Comment