Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

double(<character>) gives different result in MATLAB and Octave

Tags:

matlab

octave

MATLAB (documentation):

>> double('α')    
ans =    
   945

Octave 4.0.0, Ubuntu 16.04 (documentation):

>> double('α')
ans =    
   206   177

Why do I get different results?

Note: 'α' is a greek lowercase alpha.

like image 792
user Avatar asked Dec 08 '17 13:12

user


People also ask

Is Octave and Matlab syntax same?

MATLAB vs Octave are mainly used for the same purpose. The main difference is syntax and other features. Matlab consist of specialized toolboxes which are not part of Octave. They are not fully compatible that is code written in Matlab can crush in octave and vice versa.

How octave is different from Matlab?

MATLAB is a matrix laboratory, referred to as language used for technical computations. Octave is programming language used for numerical computations. 2. It was written in C, C++ and Java programming language.

Is octave better than Matlab?

MATLAB is probably a lot more powerful than Octave, and the algorithms run faster, but for most applications, Octave is more than adequate and is, in my opinion' an amazing tool that is completely free, where Octave is completely free.

Does Matlab code work in octave?

Octave is mostly compatible with Matlab. Most matlab functions can be made to run with very little change. With careful coding, you can get your code to run without change in Matlab and Octave.


1 Answers

This is because the default encoding in MATLAB is 'US-ASCII' (can be different depending on Locale settings) while in Octave, it is 'UTF-8'.

To confirm, here is the result from MATLAB:

>> unicode2native('α', 'UTF-8')

ans =

  1×2 uint8 row vector

   206   177

You can check your encoding with feature or slCharacterEncoding() :

feature('DefaultCharacterSet')

or

slCharacterEncoding() 

According to Mathworks, you can change your encoding with:

slCharacterEncoding(encoding)

I didn't have much luck in changing the encoding and getting the same results afterwards. It could be a bug.

like image 85
Sardar Usama Avatar answered Sep 28 '22 04:09

Sardar Usama