[37] | 1 | function n = length(q) |
---|
| 2 | % LENGTH Length of vector. |
---|
| 3 | % (Quaternion overloading of standard Matlab function.) |
---|
| 4 | |
---|
| 5 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 6 | % See the file : Copyright.m for further details. |
---|
| 7 | |
---|
| 8 | % This was written because length appears not to work correctly for arrays |
---|
| 9 | % of structs, as can be demonstrated by: |
---|
| 10 | % |
---|
| 11 | % a.x = randn(5,1), length(a) |
---|
| 12 | % |
---|
| 13 | % which gives 1, and |
---|
| 14 | % |
---|
| 15 | % a = randn(5,1), length(a) |
---|
| 16 | % |
---|
| 17 | % which gives 5, as expected. |
---|
| 18 | |
---|
| 19 | error(nargchk(1, 1, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 20 | |
---|
| 21 | if ispure(q) |
---|
| 22 | if length(x(q)) ~= length(y(q)) | length(x(q)) ~= length(z(q)) |
---|
| 23 | error('Sizes within object differ.') |
---|
| 24 | end |
---|
| 25 | else |
---|
| 26 | if length(s(q)) ~= length(x(q)) | length(s(q)) ~= length(y(q)) | length(s(q)) ~= length(z(q)) |
---|
| 27 | error('Sizes within object differ.') |
---|
| 28 | end |
---|
| 29 | end |
---|
| 30 | |
---|
| 31 | % In what follows, we use the length of the x component, not the length of the scalar part, |
---|
| 32 | % since this could be empty. Otherwise the choice is arbitrary, since the code above checks |
---|
| 33 | % that all components of q have the same length. |
---|
| 34 | |
---|
| 35 | n = length(x(q)); |
---|