matlabcomplex-numbers

matlab accumarray with complex numbers


I don't understand accumarray behaviour when passed complex numbers. I expect accumarray([1 1]', [1i 2i]') to behave like sum([1i 2i]) (for this particuar case).

It however returns 0.0000 - 3.0000i instead of 0.0000 + 3.0000i.


Solution

  • You mixed up your operators. ' is the complex conjugate transpose. Use .' to do a regular transpose. So you're doing sum([-1i; -2i]) which is indeed -3i. Calling accumarray([1 1].', [1i 2i].'), mind the dots, gives 0.0000 + 3.0000i.

    See also Why is complex conjugate transpose the default in Matlab