1 | function n = numel(q, varargin) |
---|
2 | % NUMEL Number of elements in an array or subscripted array expression. |
---|
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 | error(nargchk(1, inf, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
9 | |
---|
10 | % The built-in function numel, if applied to a quaternion array, always |
---|
11 | % returns 1. Clearly, the function should return the number of quaternions |
---|
12 | % in the array. Therefore, this is what we compute if this function is |
---|
13 | % called with a single argument (which can only be a quaternion array). |
---|
14 | |
---|
15 | if isempty(q) n = 0; end % Return zero for an empty quaternion array. |
---|
16 | |
---|
17 | if nargin == 1 |
---|
18 | n = prod(size(q)); % This gives the number of quaternions in q. |
---|
19 | else |
---|
20 | % We have more than one argument. This means varargin represents a |
---|
21 | % list of index values. See the Matlab help documentation on the |
---|
22 | % numel function for a detailed (if unclear!) explanation of what |
---|
23 | % numel has to do. It appears that this function should never be |
---|
24 | % called with this parameter profile (Matlab calls the built-in |
---|
25 | % function instead), so we trap a call with an error. |
---|
26 | |
---|
27 | error('Quaternion numel function called with varargin, unexpected.'); |
---|
28 | |
---|
29 | % If we do have to handle this case, here is how it could be done: |
---|
30 | |
---|
31 | n = numel(x(q), varargin); |
---|
32 | end |
---|