Line | |
---|
1 | function str = char(q) |
---|
2 | % CHAR Create character array (string). |
---|
3 | % (Quaternion overloading of standard Matlab function.) |
---|
4 | |
---|
5 | % Note: the Matlab char function converts arrays of numeric values into |
---|
6 | % character strings. This is not what this function does, but the Matlab |
---|
7 | % guidance on user-defined classes suggests writing a char function and |
---|
8 | % a disp/display function. This advice has been followed. |
---|
9 | |
---|
10 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
11 | % See the file : Copyright.m for further details. |
---|
12 | |
---|
13 | error(nargchk(1, 1, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
14 | |
---|
15 | [r, c] = size(q); |
---|
16 | if r > 1 | c > 1 |
---|
17 | error('Argument cannot be a vector or a matrix.') |
---|
18 | end |
---|
19 | |
---|
20 | % There are three cases to be handled. |
---|
21 | % The argument is one of: empty, a pure quaternion, a full quaternion. |
---|
22 | % The format is similar to the built in Matlab format for complex numbers. |
---|
23 | |
---|
24 | if isempty(q) |
---|
25 | str = '[]'; |
---|
26 | elseif ispure(q) |
---|
27 | str = [ num2str(x(q)) ' I + ' num2str(y(q)) ' J + ' num2str(z(q)) ' K']; |
---|
28 | else |
---|
29 | str = [num2str(s(q)) ' + ' num2str(x(q)) ' I + ' num2str(y(q)) ' J + ' num2str(z(q)) ' K']; |
---|
30 | end |
---|
31 | |
---|
Note: See
TracBrowser
for help on using the repository browser.