JuliaInterop / MATLAB.jl

Calling MATLAB in Julia through MATLAB Engine
MIT License
269 stars 63 forks source link

Better anticipate Matlabs behavior regarding integer vs float values? #211

Open Naikless opened 1 year ago

Naikless commented 1 year ago

This took me a while to figure out:

If I send data from Julia to Matlab, integer values from Julia will be cast as the corresponding integer values in Matlab. However, using Integer values in Matlab is relatively rare as per default everything is a double.

This can lead to some unexpected errors, because Matlab e.g. refuses to compute something like this:

[int64(1) int64(2)] .* [2,3]
Error using  .* 
Integers can only be combined with integers of the same class, or scalar doubles.

Not sure what the best solution here would be though. At the very least I would stress in the readme that every Julia variable that is supposed to be used by Matlab should be defined as a float, i.e. 1.0 instead of 1 unless the Matlab code specifically asks for integers.