How do I change the output color when using the disp function?

111 Ansichten (letzte 30 Tage)
David Cole
David Cole am 6 Sep. 2024
Beantwortet: Umar am 7 Sep. 2024
I would like to change the text color of the displayed text in the command window when using the disp function.
Example:
disp(['this is [' 8 'orange]' 8 ' text'])
this is orange text
this is orange text
As you can see, the color did not change.
Thanks

Antworten (2)

Image Analyst
Image Analyst am 7 Sep. 2024

Umar
Umar am 7 Sep. 2024

Hi @David Cole ,

It is not straightforward to change text color in MATLAB's command window using displ Also, after doing some research, it seems fprintf has limitations with ANSI codes and requires an environment that supports ANSI formatting. After doing some research, this is what I found at Mathworks file exchange as shown in the link below.

https://www.mathworks.com/matlabcentral/fileexchange/38252-tcprintf-ansi-colored-output-in-terminal

Also, I found out that you can use graphical functions like text for colored output in figures. By using the appropriate methods for your environment, you can achieve the desired visual effect using following code snippet below.

% Create a figure
figure;
% Display colored text in a text object
text(0.5, 0.5, 'This is orange text', 'Color', [1, 0.647, 0]); % RGB for orange
axis off; % Turn off the axis

Please see attached.

Please let me know if you have any further questions.

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by