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

81 visualizaciones (últimos 30 días)
David Cole
David Cole el 6 de Sept. de 2024
Respondida: Umar el 7 de Sept. de 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

Respuestas (2)

Image Analyst
Image Analyst el 7 de Sept. de 2024

Umar
Umar el 7 de Sept. de 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.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by