Get from Ico-github-logo

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

  • avg_quaternion_markley(Q)
    by Tolga Birdal
  • wavg_quaternion_markley(Q...
    by Tolga Birdal
  • test_avg_quat.m
    Average 100 times
  • View all files

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

5.0 | 4 ratings Rate this file 12 Downloads (last 30 days) File Size: 117 KB File ID: #40098 Version: 1.1



Tolga Birdal (view profile)


30 Jan 2013 (Updated )

This function computes the average (mean) quaternion.

| Watch this File

File Information

Since quaternions are not regular vectors, but rather representations of orientation, an average quaternion cannot just be obtained by taking a weighted mean. This function implements the work done by F. Landis Merkley to calculate the average quaternion. The algorithm is explained by F. Landis Markley at:
For this particular implementation, I would also like to reference Mandar Harshe:
While being basic and straightforward, this algorithm is compared with rotqrmean from VoiceBox and found to produce quite similar results, yet it is more elegant, much simpler to implement and follow. (Though, there might be difference in signs)

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
02 Oct 2016 Ismail Mustafa Engiz  
09 Feb 2016 Tolga Birdal

Tolga Birdal (view profile)

Dear Tobias,

Thank you for the remarks and comments.

The randomly generated qinit is always known to be positive. For the sake of comparisons using the sum of squared method, I wanted the signs to match. Assuming that the average quaternion result would not be very different from the mean of the random sampling, the signs should ideally match.

This is only done for the sake of comparison with qinit. Nothing else. If you could come up with a more fair metric, I would love to add that.

Finally, I agree that this not something I'm proud of : ) But nevertheless lets me to evaluate the quaternions, otherwise the element-wise difference might just be too large.

Comment only
09 Feb 2016 Tobias Hauber

Hey, first i want to thank you for publicly offer this algorithm as Matlab methode. But i found something in your test file "test_avg_quat" that i dont understand. In line 25 you calculate the average Quaternion and in line 28 you just override it with the absolut value of this average. The absolut Quaternion or the representet Rotation is different to the before calculated average Rotation with the Markley Methode. Did you maybe want to invert the sign so that q=-q? That wouldnt chance the Rotation but the sign. Or what is the reason for taking the absolut value?

Thanks T.

02 Jun 2014 Mosong Cheng  
30 Jan 2014 sathish  
30 Sep 2013 Tolga Birdal

Tolga Birdal (view profile)

Note that on 2001 Claus Gramkow showed that the naive mean is in fact a fair approximation of rotations:

I think re-orthagonalization using SVD after a standard averaging would suffice most applications.

Comment only
17 Aug 2015 1.1

Weighted average added.
Test function added.

Contact us