Octave should be more consistent in converting automatically char to numeric.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Octave should be more consistent in converting automatically char to numeric.

Dildar Sk
In MATLAB,

>> sind('334')
Undefined function 'sind' for input arguments of type 'char'.
 
>> cosd('2')
Undefined function 'cosd' for input arguments of type 'char'.
 
>> tand('HelLO WorLD')
Undefined function 'tand' for input arguments of type 'char'.
 
>> deg2rad('1')
Error using deg2rad (line 13)
Input must be single or double.
 
>> rad2deg('ok')
Error using rad2deg (line 13)
Input must be single or double.
 

So,most of the times MATLAB chooses not to automatically convert char value
to numerical.
But in Octave,

>> sind('334')
ans =

   0.77715   0.77715   0.78801

>> cosd('2')
ans =  0.64279
>> tand('HellO wOrLD')
ans =

 Columns 1 through 6:

   3.07768  -5.14455  -3.07768  -3.07768   5.14455   0.62487

 Columns 7 through 11:

  -1.80405   5.14455  -2.24604   4.01078   2.47509

>> deg2rad('1')
error: deg2rad: DEG must be a floating point class (double or single)
error: called from
    deg2rad at line 49 column 5
>> rad2deg('ok')
error: rad2deg: RAD must be a floating point class (double or single)
error: called from
    rad2deg at line 49 column 5

So, Octave sometimes choose to convert char value to numeric and sometimes
simply throws
error. So, I think Octave should be little more consistent in automatic
conversion.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Octave should be more consistent in converting automatically char to numeric.

Juan Pablo Carbajal-2
Hi,

I do not speak for the whole community here... that should be obivous.

Octave aims at running "every code that runs in matlab" without
modification. I am not sure there is a stand on code that *doesn't*
run on matlab.
So I guess it is rather a choice to realize that char is meant to be a
value in the ascii table rather than the value itself.


Reply | Threaded
Open this post in threaded view
|

Re: Octave should be more consistent in converting automatically char to numeric.

Sergei Steshenko
________________________________
From: Juan Pablo Carbajal <[hidden email]>
To: Dildar Sk <[hidden email]>
Cc: Help GNU Octave <[hidden email]>
Sent: Monday, March 26, 2018 11:37 AM
Subject: Re: Octave should be more consistent in converting automatically char    to numeric.



Hi,

I do not speak for the whole community here... that should be obivous.

Octave aims at running "every code that runs in matlab" without
modification. I am not sure there is a stand on code that *doesn't*
run on matlab.
So I guess it is rather a choice to realize that char is meant to be a

value in the ascii table rather than the value itself.

----------------------------------------------------------------------

'Octave aims at running "every code that runs in matlab" without

modification' - suppose there is a Matlab program checking validity of numeric user input.

Since the input can be erroneous, and the program shouldn't stop, a good way to achieve this is to use 'eval' statement and check whether it was successful through the 'CATCH' part of the 'eval' statement.

Under such circumstances Matlab will flag some user input as erroneous while Octave will accept it.

So, which of the two behaviors is correct ?

--Sergei.