문제

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'

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top