How to print symbols in matlab?

조회 수: 208 (최근 30일)
bluexdestination
bluexdestination 2013년 9월 29일
댓글: Stephen23 2021년 8월 25일
Hi,
I was wondering if I can print symbols in the command window that is not within the ranges of
char(0:255)
For example, the integral symbol which has the unicode of U+0283,or HTML (decimal) 643.
If I can accomplish this, I was wondering how it can implemented.
Thanks in advance!

답변 (4개)

Walter Roberson
Walter Roberson 2013년 9월 29일
편집: Walter Roberson 2013년 9월 29일
>> char(643)
ans =
ʃ
The limit is decimal 65300 if I recall correctly (not 65335 as one would expect.) Note that UTF-8 or UTF-16 encoding is not used
  댓글 수: 2
bluexdestination
bluexdestination 2013년 9월 29일
Hi, I realized that when I try to implement the symbol in the code below:
x = strcat (char(643),'i', '1')
the output in the command prompt doesn't display the symbol, instead it displays a space. As shown below:
x =
i1
However, in the workspace the variable shows the display I want with the integral symbol. I'm using Rmatlab 2012b is that the reason why, or is something disabled such that I cannot view symbols past char(255) in the command window?
Thanks for your help in advance.
Walter Roberson
Walter Roberson 2013년 9월 29일
You may need to change your font. Some people have also run into this if their system is configured to use a language other than English.

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


Steven Lord
Steven Lord 2019년 4월 3일
Instead of trying to display the symbols in the Command Window, consider writing your code in the Live Editor. You can insert equations into a Live Script or Live Function either via an equation editor or via LaTeX.

Zoe Herrick
Zoe Herrick 2019년 4월 3일
You can try something like this:
str = '$$ \int_{0}^{2} x^2\sin(x) dx $$';
text(1.1,0.5,str,'Interpreter','latex')

Bart McCoy
Bart McCoy 2021년 8월 25일
편집: Bart McCoy 2021년 8월 25일
Generating or Printing Unicode Characters in MATLAB:
I'm working with MATLAB 2021, but this has worked for about a year now for me.
In general, Unicode values for different symbols can be found on many sites and most publish the 4-digit HEX value. Looking at this link (Unicode Table for Greek Chars), the Unicode for Greek capital Delta (Δ) is U+0394 or 0x0394 hex.
To get the MATLAB char for Δ, just convert hex to decimal and run it through char, as shown below:
% Extract the Greek char for capital DELTA, Δ [either way works]
c = char( hex2dec('0394') ) % Use '0394' as a char string
c = char( hex2dec( sprintf('%04d', 394) ) ) % Use integer 394 and generate the 4-digit string
NOTE ON SAVING UNICODE CHARS IN .M FILES:
Before 2020 or so, you could paste these chars into a MATLAB script and save the .m file, but when close & reload the .m file, your chars appear as a square. That's because MATLAB didn't save scripts in UTF-8 format, (as I understand it).
In R2021a, MATLAB now saves .m files as UTF-8 by DEFAULT. I have personally verified that I can paste Unicode chars (e.g. all lower/uppercase Greek letters) into a script, save it, close file, reload, and they all appear fine. Someone in this thread indicated that R2020a was when UTF-8 became the default and it actually worked.
Run "ver" to see your MATLAB version or do a File ==> Save As, to see if the default file format for .m files is UTF-8 (required to save unicode chars)
  댓글 수: 1
Stephen23
Stephen23 2021년 8월 25일
Note since version R2019b you can enter hex values directly, so no need to use HEX2DEC:
c = char(0x394)
c = 'Δ'

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by