Hi,
how can I easy write "Set omega" into static text in GUI, where omega should be a greek letter?
Thanks for help

 採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 6 日
編集済み: Walter Roberson 2013 年 4 月 8 日

2 投票

The easiest is to use a text() control instead of uicontrol('Style','text'). For text() controls, see http://www.mathworks.co.uk/matlabcentral/answers/14751-greek-alphabet-and-latex-commands-not-a-question
If you must use a uicontrol, then unless there is a method at the java level, you cannot do it with Style 'text' or 'edit'. You can, however, use 'style' 'Push' with 'enable' 'off', and then use html, such as
h = uicontrol('Style', 'push', 'enable', 'off', 'units', 'norm', 'position', [0 0 1 .1], 'String','<FONT COLOR="red">hello &omega;')

8 件のコメント

john
john 2013 年 4 月 8 日
I realy need use gui. Your code got me hello ? ...not hello w.
It is possible to use it for code:
set(handles.text, 'String','<FONT COLOR="red">hello ω');
Walter Roberson
Walter Roberson 2013 年 4 月 8 日
Dang editor here... I have adjusted what I wrote so that it shows up correctly here.
john
john 2013 年 4 月 8 日
It is possible to use it for code:
set(handles.text, 'String','<FONT COLOR="red">hello ω');
???
Walter Roberson
Walter Roberson 2013 年 4 月 8 日
Yes. But you need to use ω rather than the character ω
set(handles.text, 'String','<FONT COLOR="red">hello &omega;');
john
john 2013 年 4 月 8 日
編集済み: Walter Roberson 2013 年 4 月 8 日
I got <HTML><FONT COLOR="red">hello &omega;&lt/HTML>, not hello w???
Walter Roberson
Walter Roberson 2013 年 4 月 8 日
Did you switch to pushbutton? I noted above that you cannot do it with style 'text' or 'edit' and need to switch to 'push' with 'enable' 'off'
john
john 2013 年 4 月 8 日
ok, thanks, it works
Miguel
Miguel 2016 年 3 月 17 日
Do you know how to remove the border of that push button which is inside the uicontrol?

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

その他の回答 (1 件)

Timothy Plummer
Timothy Plummer 2017 年 1 月 4 日

2 投票

So there is an easier way to do this, but you need to know the Unicode number for the character you want, and preferably in decimal notation. The simplest way would be to call the Unicode number, which is typically shown in hexadecimal, and call:
Unicode = ''; %%insert Unicode
char(hex2dec(Unicode))
Char will output the Unicode character which can be inserted into the uicontrol correctly. So the code you would need would be:
uicontrol('style','text','string',['Set ',char(hex2dec('3a9'))]);
Let me know if this helps.

3 件のコメント

Walter Roberson
Walter Roberson 2017 年 1 月 5 日
This depends on which MATLAB release you are using. In R2014a and earlier, characters beyond position 255 would never appear.
In R2014b and later, Unicode in uicontrol is supported, and you can even directly include the characters in the strings if you find a way to enter them. For example,
uicontrol('style','text', 'string', 'Set Ω', 'Units','norm','Position',[.1 .1 .3 .3])
However, whether Unicode characters will be saved in your .m files depends upon your MATLAB release and your operating system and your region settings, so coding in terms of char(hex2dec()) might be a practical necessity. Another approach is, for example,
uicontrol('style','text', 'string', sprintf('Set \x3a9'), 'Units','norm','Position',[.1 .1 .3 .3])
Diaa
Diaa 2017 年 3 月 7 日
@Walter Roberson Could you refer me to the specific part of MATLAB documentation of printing characters like your approach?
\x3a9
Walter Roberson
Walter Roberson 2017 年 3 月 7 日
Diaa: see https://www.mathworks.com/help/matlab/ref/sprintf.html#input_argument_formatSpec and scroll to "Text Before or After Formatting Operators" in the Special Characters table, the entry
Character whose ASCII code is the hexadecimal number, N \xN

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

カテゴリ

ヘルプ センター および File Exchange で Labels and Annotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by