Clear Filters
Clear Filters

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

71 views (last 30 days)
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

Answers (2)

Image Analyst
Image Analyst on 7 Sep 2024 at 3:45

Umar
Umar on 7 Sep 2024 at 3:56

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.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!