How can I show partially colored text in Matlab?

◇◆丶佛笑我妖孽 提交于 2019-12-10 20:57:49

问题


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'


回答1:


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!



来源:https://stackoverflow.com/questions/8810815/how-can-i-show-partially-colored-text-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!