Greek character in script turned to a square or a question mark - any ideas why?

8 views (last 30 days)
I copied a script from an older computer with Matlab 2012b to a new computer with Matlab 2017a and when I opened it, a Greek character 'μ' was encoded as a little square (maybe missing font). After Installing the Greek language option in MS Windows and typing in its place the letter μ, running the script reported an error (wrong matrix dimensions). So I reloaded the saved script and the character μ had now been replaced by a questionmark. Does anyone know what is going on? I have not witnessed this before. The faulty character encoding may have nothing to do with Matlab itself.

Answers (3)

maiaL
maiaL on 3 Aug 2020
You can refer to this if you want to print greek and other special characters. But I don't think you can have these characters within the code itself.

Nick Aggelopoulos
Nick Aggelopoulos on 4 Aug 2020
Edited: Nick Aggelopoulos on 4 Aug 2020
The line is
while infoHeadr (pe) ~='μ'
pe=pe+1;
The matlab script was running fine on other computers. On this new computer, the μ was instead displayed as a little square before I installed the Greek keyboard. After that it was displayed as a μ
Matlab reported an error (Index exceeds matrix dimensions) when reaching this line:
On re-opening the saved file, the line instead of a μ has a questionmark
while infoHeadr (pe) ~='?'
The matrix dimension error of course is reported whether there is a little square or a questionmark and there rather seems something amiss about the character encoding. It is likely the error has something to do with encoding or something else unrelated to matlab, although the result is that it prevents the matlab script from being executed. On the other computers, the μ is never replaced automatically by those other things.

Walter Roberson
Walter Roberson on 4 Aug 2020
Edited: Walter Roberson on 4 Aug 2020
R2020a is the first release that handles UTF8 encoding in a way that is natural to the user.
In releases before that, you had to use hacks and obscure calls to tell MATLAB that you were going to use non-ASCII. And on your new computer, you have not used those obscure settings.
My recommendation would be to upgrade to R2020a.
  4 Comments
Walter Roberson
Walter Roberson on 7 Aug 2020
while infoHeadr (pe) ~='μ'
pe=pe+1;
That code runs off the end of array if the character is never found.
Unrecognized utf8 for μ would be interpreted as a pair of bytes, at least one of which was non-printable. That would then be comparing two different characters to each array entry, which is guaranteed to fail because no one value can be equal to two different things. If you use a good programming editor you can ask to see all the bytes rendered to see what is stored there. https://superuser.com/questions/558781/show-hexadecimal-ascii-codes-on-notepad-6-3
Nick Aggelopoulos
Nick Aggelopoulos on 10 Aug 2020
Edited: Walter Roberson on 10 Aug 2020
Thanks again for your help. Just in case it is of help to others, the following edit in lcdata.xml, a file found in MATLAB/bin root directory, solved my problem (I also had to delete an old cached file called by the program when searching for the header info):
<?xml version="1.0" encoding="UTF-8" ?>
<!-- MathWorks Locale Database -->
<!-- File Name: lcdata.xml -->
<!-- Copyright 2007-2016 The MathWorks, Inc. -->
<lcdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="lcdata.xsd">
<!-- Note: -->
<!-- This locale database is used to customize the MathWorks locale database. -->
<!-- Codeset entry example -->
<!-- <codeset> -->
<!-- <encoding name="StandardEncodingName" jvm_encoding="JavaEncodingName"> -->
<!-- <encoding_alias name="AliasName"/> -->
<!-- </encoding> -->
<!-- </codeset> -->
<!-- Locale entries example -->
<!-- <locale name="StandardLocaleName" encoding="EncodingName" xpg_name="XpgLocaleName"> -->
<!-- <alias name="AliasName"/> -->
<!-- "region_alias" is only for Mac -->
<!-- <region_alias name="RegionAliasName"/> -->
<!-- </locale> -->
<codeset>
<encoding name="UTF-8">
<encoding_alias name="US-ASCII" />
</encoding>
</codeset>
</lcdata>

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!