matlabuser-interfacetextmatlab-guide

Change color of a part of string in MATLAB


Suppose that we have these codes :

String_1 = 'hi';
String_2 = 'You';
set(handles.text,'String',[String_1',Who are ' String_2 '?']); %% handles.text refers to a static text in GUI

String_2 should be red in sentence and other words should be default (black). I know that I can create a separate static text for String_2 and change the color of it manually but Is anyway to change the color of String_2 in above structure?

Thanks.


Solution

  • To color part of the string, you cprintf function.

    You can reference to this: http://undocumentedmatlab.com/blog/cprintf-display-formatted-color-text-in-command-window