Question

I am trying to color some alphabets in a string based on input alphabet given. Can anyone suggest me how to achieve it ? As I am new to this.

Suppose that I have the following string: "AUSTRALIA"

INPUT: A
OUTPUT: (A in red)'A'USTR(A in red)'A'LI(A in red)'A'

Was it helpful?

Solution

If you want to show it as text on axes (GUI), use the text command and Latex formatted strings

text('string','{\color{red} A}ustralia')

You can read about Latex commands here.
Alternatively, there is an undocumented functionality for some UI controls, mentioned in Yair Altmans great website.

That is the way to do it (Taken directly from his site)

uicontrol('Style','list', 'Position',[10,10,70,70], 'String', ...
{'<HTML><FONT color="red">Hello</Font></html>', 'world', ...
 '<html><font style="font-family:impact;color:green"><i>What a', ...
 '<Html><FONT color="blue" face="Comic Sans MS">nice day!</font>'});

In order to actually find the letters instances, use the strrep command.

strrep(lower('Australia'),'a','{\color{red}a}')

There is a flaw here, related to capital letter, I am sure that you can work it out!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top