0

Suppose I have a cell array like the following:

mycell = 

[-1.6411e-16 + 1.4863e-19i]    [         0.6450 + 0.6433i]
[         0.6450 + 0.6433i]    [-1.6411e-16 + 1.4863e-19i]

I want it to be a matrix, so I use the command cell2mat:

>> mymatrix = cell2mat(mycell)

mymatrix =

  -0.0000 + 0.0000i   0.6450 + 0.6433i
   0.6450 + 0.6433i  -0.0000 + 0.0000i

I certainly get the result I expect in terms of cell arrays and matrices, but why -1.6411e-16 + 1.4863e-19i is rounded to -0.0000 + 0.0000i?

And, the most important thing, how could I avoid this situation?

Thank you.

EDIT: I've figured out the solution by myself.

baister
  • 283
  • 2
  • 9

1 Answers1

1

There is no loss of precision.

Just set the scientific notation format (in short way, shortE, to get exactly the same numbers which appear in the cell array):

>> format shortE
>> mymatrix

mymatrix =

  -1.6411e-16 + 1.4863e-19i   6.4503e-01 + 6.4328e-01i
   6.4503e-01 + 6.4328e-01i  -1.6411e-16 + 1.4863e-19i
baister
  • 283
  • 2
  • 9