Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

how to give color to an output text

Asked by Elysi Cochin

Elysi Cochin (view profile)

on 8 Apr 2013

i saved my output in txt file.....

 myOutput = Image Processing is interesting

i wanted to display the word "Process" in green color and the remaining words in black color itself....

i found a link in which we can format the text in different ways....

http://www.mathworks.in/matlabcentral/fileexchange/24093-cprintf-display-formatted-colored-text-in-the-command-window/content/cprintf.m

but in all those examples we give the full text to change color... but i want only a portion of the text to change its color...

if found the starting position of Process and the position upto which i want to change color... but i dont know how to keep the other text colors black and "Process" only green...... please can someone help me solve it.... i need the output to be displayed either in command window or txt file.... but the only thing is the change in color shud be there.....please do reply....

0 Comments

Elysi Cochin

Elysi Cochin (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Cedric Wannaz

Cedric Wannaz (view profile)

on 8 Apr 2013
Edited by Cedric Wannaz

Cedric Wannaz (view profile)

on 8 Apr 2013
Accepted answer

Use a combination of FPRINTF and CPRINTF, without outputting CR/LF before the "final" end of line.

 >> fprintf('This is a ') ; cprintf('_red', 'colorful ') ; fprintf('example!\n') ;

but be aware that CPRINTF is rather slow.

 >> tic ; for k = 1:1e2, fprintf('.') ; end ; fprintf('\n') ; toc
 ....................... ..
 Elapsed time is 0.001758 seconds.
 >> tic ; for k = 1:1e2, cprintf('_red', '.') ; end ; fprintf('\n') ; toc
 ....................... ..
 Elapsed time is 1.458687 seconds.

0 Comments

Cedric Wannaz

Cedric Wannaz (view profile)

Answer by Image Analyst

Image Analyst (view profile)

on 8 Apr 2013

I know this isn't what you want, but in case others want to know how to "burn" colored text into images, see this link : http://www.mathworks.com/matlabcentral/fileexchange/38721-embed-text-and-graphics-in-an-image

0 Comments

Image Analyst

Image Analyst (view profile)

Contact us