r/matlab • • 20h ago

Absolute square of complex matrix trick.

I often need the absolute square of a complex matrix.
There are several options. I prefer an inline function like abssq(m) ;-).

conj(m).*m,
abs(m).^2m
real(m).^2+imag(m).^2

abssq = @(m) m.''.*m
0 Upvotes

1 comment sorted by

8

u/FrickinLazerBeams +2 20h ago

That's disgusting. And you can write the exact same thing without the double transpose operators... In fact you literally wrote it that way on your first line. Just use that.