Using transpose versus ctranspose in MATLAB

Interesting question!

I would definitely say it’s good practice to use .' when you just want to transpose, even if the numbers are real and thus ' would have the same effect. The mains reasons for this are:

  1. Conceptual clarity: if you need to transpose, just transpose. Don’t throw in an unnecessary conjugation. It’s bad practice. You’ll get used to writing ' to transpose and will fail to notice the difference. One day you will write ' when .' should be used. As probable illustrations of this, see this question or this one.

  2. Future-proofness. If one day in the future you apply your function to complex inputs the behaviour will suddenly change, and you will have a hard time finding the cause. Believe me, I know what I say1.

Of course, if you are using real inputs but a conjugation would make sense for complex inputs, do use '. For example, if you are defining a dot product for real vectors, it may be appropriate to use ', because should you want to use complex inputs in the future, the conjugate transpose would make more sense.

1 In my early Matlab days, it took me quite a while to trace back a certain problem in my code, which turned out to be caused by using ' when I should have used .'. What really got me upset is, it was my professor who had actually said that ' meant transpose! He forgot to mention the conjugate, and hence my error. Lessons I learned: ' is not .'; and professors can tell you things that are plain wrong 🙂

Leave a Comment