User Tools

Site Tools


techs:programming:learn-matlab

Learn MATLAB

Always use UTF-8 in Matlab

Always remember this before actually writing or modifying any code.

How: Check the current locale setting: feature('locale'). If anything is not **.UTF-8, better to change it to.

Modify the configuration file lcdata.xml accordingly to change the coding to UTF-8.

  • MacOS: Rename matlab.app/bin/lcdata-utf8.xml to lcdata.xml
  • Windows: Similar
  • Linux: I don't know yet.

Why: Because UTF-8 is unified across platform. Using other encodings like GB2312, you are doomed to lose all the non-English comments somewhere in the future.

Default to UTF-8 since R2020a?

https://www.mathworks.com/matlabcentral/answers/482380-how-to-set-the-encoding-of-matlab-m-files-to-be-utf8#answer_627989
As of R2020a, the MATLAB Editor will default to saving new files using UTF-8. When opening existing files, the Editor and other functions like type or fopen automatically determine the current encoding. One can explicitly specify that the file should be saved using UTF-8 using the Save As dialog.

Not 100% sure about this, but it sounds like a good start for MATLAB.

MATLAB Inconsistency

Matlab seems inconsistent among different platforms and versions.

My simulation using GPz can replicate iteself with a specific combination of platform (macOS or win10) and version (R2019a, R2020a, or R2020b). But the results among different combinations are different, in most case very slightly.

Helpful Dicussions

Are MATLAB's inbuilt functions and official toolboxes cross-platform consistent?
You may also have slightly different results as of BLAS differences. When using e.g. optimization routines, this can result in large differences. The robustness is depending on data and algorithms.

This sounds exactly like my problem.

techs/programming/learn-matlab.txt · Last modified: 2021/06/14 05:32 by foreverph