Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB automatically converts double to int without explicit cast

I would let the output speak for itself:

>> numFiles, meanTangle, sdTangle

numFiles =

         526


meanTangle =

    0.4405


sdTangle =

    0.1285

Now, when I create a vector out of these variables:

>> [numFiles meanTangle sdTangle]

ans =

         526           0           0

Also, just for clarification:

>> class(numFiles)

ans =

int32

>> class(meanTangle)

ans =

double

>> class(sdTangle)

ans =

double

Why does MATLAB convert floats (meanTangle and sdTangle) to int without cast?

like image 561
abhinavkulkarni Avatar asked Jan 15 '23 20:01

abhinavkulkarni


1 Answers

It converts all of your doubles to ints because your array contains a single int. This has to do with a precision issue.

It converts the entire array into type int32:

>> class(ans)

ans =

int32
like image 197
MrHappyAsthma Avatar answered Feb 12 '23 09:02

MrHappyAsthma