solvesak
solvesak

Reputation: 166

How can I show partially colored text in Matlab?

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'

Upvotes: 3

Views: 3431

Answers (1)

Andrey Rubshtein
Andrey Rubshtein

Reputation: 20915

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!

Upvotes: 5

Related Questions