Rev | Line | |
---|
[37] | 1 | function c = horzcat(varargin) |
---|
| 2 | % HORZCAT Horizontal concatenation. |
---|
| 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 | if length(varargin) == 1 |
---|
| 9 | c = varargin{1}; % We have been passed one argument, nothing to do! |
---|
| 10 | return |
---|
| 11 | end |
---|
| 12 | |
---|
| 13 | % This is implemented recursively for simplicity, as it is unlikely to be |
---|
| 14 | % used for more than a few arguments. |
---|
| 15 | |
---|
| 16 | a = varargin{1}; |
---|
| 17 | b = varargin{2}; |
---|
| 18 | |
---|
| 19 | if isempty(b) |
---|
| 20 | c = a; return; |
---|
| 21 | elseif isempty(a) |
---|
| 22 | c = b; return; |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | if ~isa(a, 'quaternion') | ~isa(b, 'quaternion') |
---|
| 26 | % We probably could handle this but for now we don't ... |
---|
| 27 | error('Cannot concatenate quaternion with non-quaternion arrays.') |
---|
| 28 | end |
---|
| 29 | |
---|
| 30 | if xor(ispure(a), ispure(b)) |
---|
| 31 | % Again, we could do it, but the code would be more complex ... |
---|
| 32 | error('Arrays to be concatenated must be both pure or both full.'); |
---|
| 33 | end |
---|
| 34 | |
---|
| 35 | if ispure(a) & ispure(b) |
---|
| 36 | c = quaternion( [x(a) x(b)], [y(a) y(b)], [z(a) z(b)]); |
---|
| 37 | else |
---|
| 38 | c = quaternion([s(a) s(b)], [x(a) x(b)], [y(a) y(b)], [z(a) z(b)]); |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | if length(varargin) == 2 |
---|
| 42 | return |
---|
| 43 | else |
---|
| 44 | c = horzcat(c, varargin{3:end}); |
---|
| 45 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.