フィルターのクリア

How can I get text in figures to display symbols?

22 ビュー (過去 30 日間)
David Holman
David Holman 2017 年 6 月 6 日
コメント済み: Kevin Snyder 2018 年 2 月 13 日
I know how to display greek letters in a plot label using xlabel and ylabel, but when I try to get other text in a figure (not on a plot) to display greek letters or other symbols it doesn't work. When I use:
uicontrol('Style','text','Units','pixels','Position',[1557 970 135 20], ...
'String','\lambda','FontSize',10);
the result that's displayed is "\lambda", not the small case greek letter. I'm also trying to display a degree symbol and the same thing happens when I use "\circ", and I have to use a * in the mean time.
Any suggestions? Thanks, Dave

採用された回答

Walter Roberson
Walter Roberson 2017 年 6 月 6 日
編集済み: Walter Roberson 2017 年 6 月 9 日
You can set the uicontrol style to push or listbox or radio or toggle or checkbox or popup (but not text or edit). Then you can set the String property to '<HTML>λ' . You might also want to set the Enable property to off.
  5 件のコメント
Walter Roberson
Walter Roberson 2017 年 7 月 20 日
ASCII was never defined beyond 127. After that you are into ISO 8896-1 or whatever is supported by the font you are using.
MATLAB uses Unicode code points up to 65535. I find fileformat.info to have useful tables for detailed information, such as http://www.fileformat.info/info/unicode/char/b0/index.htm
The ultimate authority is unicode.org
Google is pretty good at finding information about individual symbols; for example search for "unicode degree symbol" or search for "unicode 176" or search for "U+00B0" (you do not need any other keywords if you know the hex code point)
Kevin Snyder
Kevin Snyder 2018 年 2 月 13 日
Sorry to dig this up, I was having a problem displaying Greek symbols in a table header when I came across this post. I thought I would come back with my solution because it raised a question:
Is there any particular reason or convention converting the character to a string would not work?
This is what worked for me when changing properties of a uitable:
infoTable.ColumnName = {'Sweep '+string(char(955))+' [nm]',...};

サインインしてコメントする。

その他の回答 (2 件)

Yair Altman
Yair Altman 2017 年 7 月 14 日
編集済み: Walter Roberson 2017 年 7 月 14 日
%show the 'for all' and 'beta' symbols
labelStr = '<html>&#8704;&#946; <b>bold</b> <i><font color="red">label</html>';
jLabel = javaObjectEDT('javax.swing.JLabel',labelStr);
[hcomponent,hcontainer] = javacomponent(jLabel,[100,100,40,20],gcf);
The idea here is to use HTML formatting to add the special characters. This is in line with Walter Roberson's answer, but would be displayed in a text label rather than a button.
As an alternative, you could set the HTML string on a button uicontrol, and then remove its border (which provides the 3D visual illusion) as explained here:

dpb
dpb 2017 年 6 月 6 日
Unfortunately, the uicontrol objects do not expose an 'Interpreter' property as does the text object or even labels.
Unless Yair has some secret tricks on his "Undocumented Matlab" site, I think the only option would be to revert back to the text object to actually do the display if there isn't an installed font with the characters you want without resorting to TeX.
  1 件のコメント
David Holman
David Holman 2017 年 6 月 9 日
Unfortunately, text only allows text on a plot, and I'm trying to add text to a figure that's "not on a plot". Thanks for pointing out the "Undocumented Matlab" site, I bookmarked it. Dave

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by