MATLAB Answers

Reading greek letters!

22 views (last 30 days)
Stephen Hall
Stephen Hall on 20 Nov 2019
Answered: Adam Danz on 20 Nov 2019
I need to read text from an EXCEL file that will include greek letters in some cells. While I can transform the letters (e.g., spelling out "alpha" in place of the actual letter), I need to preserve the content. Currently, when I read the file using readcell, I get the greek letters in the text, but as soon as I try to do anything with them they get substituted with question marks. This is problematic, as I need to make decisions based on the text, and can't do that if every theta, eta, and nu is just going to become identical ?'s.
So, any ideas?
EDIT: For clarification on "...but as soon as I try to do anything..."
Below, the word tau, by itself, is the greek letter itself
>>Text = readcell(File,'Sheet',Sheet);
>>VN = char(Text(2,1));
VN =
>>switch VN
case tau
A = 'tau';
A = 'ERROR';
A =
Please note that when I call VN, I see the letter tau on the screen. When I save it in an .mat file and reopen, VN = '?'.
In essense, I need a way to do the reverse of what char(945) would do - where char(945) takes a MATLAB-manipulatable value and produces a greek letter, I need something that will take a greek letter and produce a MATLAB manipulative value (like Unicode or '\alpha').


Show 2 older comments
Jeremy Hughes
Jeremy Hughes on 20 Nov 2019
To be pedantic, ASCII is only the [0 127] range of characters. Beyond 127, everything is "extended ascii" which means nothing by itself. You need to know what encoding the characters are in. <end pendantry>
In this case, the TAU character is the UTF-16 representation (which is how MATLAB stores characters). The "?" showing up in display can mean one of two things:
The character isn't recognized from the encoding it's stored in the file as, or the FONT you're using doesn't have the character available.
To tell which, use double(TAU_CHAR) should show you the UTF-16 value(s) for the character:
If it's
ans = 26, then MATLAB has replaced the character, as it didn't know what to do with it. Otherwise, if it there's a number other than 26, the data is there, but the FONT doesn't have an entry for that UTF-16 character.
Stephen Hall
Stephen Hall on 20 Nov 2019
Adam, your comment is sufficient for an answer - I did not know that double would give the code for the letter. It does, and my problem is now resolved.
Thanks, both!
Adam Danz
Adam Danz on 20 Nov 2019
@Jeremy Hughes, thanks for the clarification; pedantry welcomed!
@Stephen Hall, I'll copy an improved version of my comment to the answers section so your question appears as answered.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 20 Nov 2019
[continued from comment section under the answer]
If you're just referencing single greek letters, you could use the double() value for those characters.
For example, the double() value for tau is
value = double('τ') % 964, lower case
value = double(upper('τ')) % 932, upper case
So when you read in the letters, you can instantly convert them to their numeric values.
VN = double(Text{2,1});
and then in your switch statement,
switch VN
case [932, 964] % for upper and lower cases
% code


Sign in to comment.

More Answers (0)

Sign in to answer this question.

Translated by