Why do complex matrices display real elements as "1.23e45 + i" when format is set to eng?

There's probably a reasonable reason for this behavior, but I can't seem to understand why this;
format short eng
foo = [2 + 1*i, 3]
prints
foo =
2.0000e+000 + 1.0000e+000i 3.0000e+000 + i
IE. why 0.0000e+000 isn't printed before the second 'i' character. As it is now the (IMHO) reasonable assumption is that foo(2) is in fact 3+1*i, rather than 3+0*i.
This behavior is not present with the default format mode, where the output is instead an, arguably more reasonable,
foo =
2.0000 + 1.0000i 3.0000 + 0.0000i
Thanks!

3 Comments

@Jonathan Lock: what OS and MATLAB version are you using ?
MATLAB 2012b:
>> format short
>> foo = [2 + 1*i, 3]
foo =
2.0000 + 1.0000i 3.0000
>> format short eng
>> foo
foo =
2.0000e+000 + 1.0000e+000i 3.0000e+000
This is on 9.0.0.341360 (R2016a), running on linux (4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux). Though FWIW Guillaume states it's a bug (which is what I was hoping for as the current behavior is very confusing ;) ).

Sign in to comment.

 Accepted Answer

I can reproduce it with 2016a and 2016b pre.
It is clearly a bug which I'll report to mathworks.

4 Comments

Ah, that makes sense. FWIW I'm running 9.0.0.341360 (R2016a) on linux (4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux). Thanks for the help!
I've submitted a bug report and will update here when I get a reply from MathWorks.
I've had confirmation by MathWorks that it is indeed a bug. No ETA for a fix.
Thanks for the update! Always relieving when the issue isn't PEBCAK-based =)

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!