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

조회 수: 80 (최근 30일)
David Cole
David Cole 2024년 9월 6일
답변: Umar 2024년 9월 7일
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

답변 (2개)

Image Analyst
Image Analyst 2024년 9월 7일

Umar
Umar 2024년 9월 7일

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.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by