matlab_kernel icon indicating copy to clipboard operation
matlab_kernel copied to clipboard

unintelligible codes

Open yangtzech opened this issue 3 years ago • 6 comments

When the matlab code is wrong, the tips can't show correctly. My pc's default language is Chinese. I don't know if that's the reason.

wrong one: x=1:1:100; y=10*x*x; plot(x,y) title('test')

correct one: x=1:1:100; y=10*x.*x; plot(x,y) title('test')

tip: image

yangtzech avatar Jun 23 '21 14:06 yangtzech

Hi, this seems to be something to do with encoding. Which Python version are you using? I recall that "MATLAB engine for Python" supports python 2.7, which might cause problems when encountering Unicode Characters (like Chinese characters), but there should be no problems with Python 3.x versions.

RibomBalt avatar Mar 26 '22 06:03 RibomBalt

Hi, this seems to be something to do with encoding. Which Python version are you using? I recall that "MATLAB engine for Python" supports python 2.7, which might cause problems when encountering Unicode Characters (like Chinese characters), but there should be no problems with Python 3.x versions.

It seemed to be python 3.8 and MATLAB 2020b. I just tried it again and the error could display correctly this time with python 3.8 and MATLAB 2021b. Thanks for your help anyway!

yangtzech avatar Mar 26 '22 10:03 yangtzech

I encountered a similar problem: fprintf('→\n') produces an entirely different symbol in the output.

image

That symbol is "Non-printable U+001A".

Here is the produced cell:

  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001a\n"
     ]
    }
   ],
   "source": [
    "fprintf('→\\n')"
   ]
  },

My system: Debian GNU/Linux 11.6, kernel 5.10.0-21-amd64 Locale LANG=en_US.UTF-8. MATLAB 9.13.0.2166757 (R2022b) Update 4 Python 3.10

allefeld avatar Mar 25 '23 19:03 allefeld

The problem seems to be related to MatlabKernel._execute_async. An extremely hacky workaround is to comment out the import of pipes from wurlitzer in kernel.py:

# try:
#     from wurlitzer import pipes
# except Exception:
#     pipes = None
pipes = None

allefeld avatar Jul 13 '23 00:07 allefeld

Dug a little deeper: The problem is caused by a bug in the Matlab engine for Python:

https://github.com/mathworks/matlab-engine-for-python/issues/34

allefeld avatar Sep 12 '23 19:09 allefeld

Thanks @allefeld for the info!

dsblank avatar Sep 12 '23 20:09 dsblank