How to get Greek letters in text in an IMAGE using Inserttext?

조회 수: 4 (최근 30일)
Steven
Steven 2016년 6월 13일
답변: Walter Roberson 2016년 6월 14일
Hi I want to use text with Greek letter in an image (use text as part of the image) using "Inserttext" as suggested by Mathworks. But I cannot get Greek letters there, since Interpreter (latex) is not one of this function's properties. What can I do? This is the code I use (I have to use sprintf):
imgOut = insertText(imgOut, [10 100], sprintf(['a=' num2str(i,'%0.4f \alpha') ],i))
Note: I tried \alpha or \\alpha but it did not work either. Thank you.
Steven

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 14일
You will need to render the character to a file or to an array, and then insert that array into the image.
Up to and including R2014a (but not later), you can work like this. Caution: this uses some magic smoke to do the job!
%use the decimal unicode character number, but only a subset is supported
%the use of HTML is documented magic... documented somewhere or other
%but you have to be aware it does not work for edit or text uicontrols
h = uicontrol('style', 'push', 'String', '<HTML>&#945;');
%now shrink the size to just what is needed to contain the letter
%there is some slinky stuff about Extent working differently on different operating systems
%so you might need to fiddle a bit.
set(h, 'Position', get(h, 'Extent'));
%now use twice-magic incantations to render the uicontrol to an array
alpha_img = getPrintImage(handle(h));
Now you can store alpha_img as needed into the image you are building up.
If you do this for a number of different characters, you can re-use the same uicontrol and set its String differently. You should expect that the Extent will vary from character to character if you are using a proportional font.

추가 답변 (1개)

Greg Dionne
Greg Dionne 2016년 6월 13일
Not sure what version of MATLAB you have, but you can try unicode.
Does char(945) work for you?
sprintf('%s',char(945))
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 6월 14일
The support for inserting unicode was not until at least R2014b.
Steven
Steven 2016년 6월 14일
Thank you Walter. So there is no other way?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by