Changing the number of decimal points for a complex double array

9 views (last 30 days)
Hello all ,
I am calculating the eigen vectors for a matrix , the output of the function stores the result as a complex double. but the problem is that it saves only to the 4th decimal point and rounds up . for example : instead of -0.99995+0.00000j it is stored as -1.0000+0.0000j . This is a problem as when it tries to save 0.00003+0.00690j as 0.0000+0.0069j. When I display the output matrix in the command window it shows the variable normally as double-precision floating-point values that are 8 bytes (64 bits). but when saving in the workspace , it does the rounding . This can be very critical as it these calcuations are related to sensitivity analysis to power system. The code used is simply as follows:
A=[ -1 0 -990;
0.04714 -0.4762 0;
0 100 -100];
e=eig(A);
[V,D,W]=eig(A);
and the result in the command window as follows:
V =
Columns 1 through 2
-0.999952261875921 + 0.000000000000000i -0.999952261875921 + 0.000000000000000i
0.000027567894396 + 0.006899820799505i 0.000027567894396 - 0.006899820799505i
0.000501495829522 + 0.006900303189568i 0.000501495829522 - 0.006900303189568i
Column 3
0.994990280675026 + 0.000000000000000i
-0.000469071210390 + 0.000000000000000i
0.099970602351055 + 0.000000000000000i
but in the work space saved as follows:
Capture21.JPG
Can anyone please help i how to save that matrix in the same format as it is computed ? .Thanks in advance .
  3 Comments
Abdelrahman Elhawash
Abdelrahman Elhawash on 7 Apr 2019
Thanks for your answer , but it didnot solve the problem . I think it just affects the result in the command window not how the variable is stored in the workspace.
John D'Errico
John D'Errico on 8 Apr 2019
No. MATLAB does indeed store a number as a double in more than 4 digits. Format does only change how the number is displayed. But nothing impacts how many digits are stored as a double.
When you look at the number in the workspace browser, that is not in fact how it is stored!

Sign in to comment.

Accepted Answer

David Wilson
David Wilson on 8 Apr 2019
Are you sure rounding is going on?
When you view the workspace, sure it shows you the truncated/rounded version on the screen, but that does not mean it is stored internally that way.
For example if you "ctrl-c" copy the (2,1) element of V from the workspace browser, and then "ctrl-v" paste into the workspace, I get
>> [2.75678943956489e-05 + 0.00689982079950539i]
ans =
0.000027567894396 + 0.006899820799505i
which is accurate to full machine precision. What you see in the workspace is not fully what's stored.
  3 Comments
John D'Errico
John D'Errico on 8 Apr 2019
Edited: John D'Errico on 8 Apr 2019
Note that in the workspace variable browswer, there is a tab called view. In there, we can change the display format used by the browser. This is apparently not controlled by the format command.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 8 Apr 2019
Go into preferences for workspace and change the default display format. The default format for the workspace viewer is not affected by the "format" command.

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!