Unfortunately, there is no official way to do this. However, you can use Yari Altman cprintf() . It abuses the undocumented Matlab features to do exactly what you want.
You can read more at the famous Matlab Unregistered Blog .
An example image in FEX is as follows:

EDIT: Theoretically, if cprintf works as expected, the following should work:
C=strsplit(s,'E'); cprintf('black',C{1}); for ii=2:size(C,2) cprintf('err','E'); cprintf('black',C{ii}); end cprintf('black','\n');
However, in Matlab 2014b it does not give good results. I found out that it does not work properly when there is one character to format.
If you replace "E" with "EE", work ...
EDIT2: I left a comment for Jari Altman. I hope he can, if he can, fix it.
source share