[37] | 1 | function count = fprintf(FID, format, A) |
---|
| 2 | % FPRINTF Write formatted data to file. |
---|
| 3 | % (Quaternion overloading of standard Matlab function.) |
---|
| 4 | % |
---|
| 5 | % Only one quaternion argument is permitted, unlike the standard |
---|
| 6 | % Matlab function. The FID parameter may be omitted, in which case |
---|
| 7 | % the output is sent to the standard output. |
---|
| 8 | % |
---|
| 9 | % The output is formatted with one quaternion per line of output. |
---|
| 10 | % Spaces are automatically inserted between each of the components |
---|
| 11 | % of each quaternion, and a \n is automatically inserted after each |
---|
| 12 | % quaternion value output. The format string supplied should therefore |
---|
| 13 | % not include spaces or \n. |
---|
| 14 | |
---|
| 15 | % Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan. |
---|
| 16 | % See the file : Copyright.m for further details. |
---|
| 17 | |
---|
| 18 | error(nargchk(2, 3, nargin)), error(nargoutchk(0, 1, nargout)) |
---|
| 19 | |
---|
| 20 | if nargin == 2 |
---|
| 21 | |
---|
| 22 | % Only two parameters have been supplied. The missing one must |
---|
| 23 | % be the FID, since the other two cannot be omitted. Therefore |
---|
| 24 | % shuffle the parameters to the right, and supply the default |
---|
| 25 | % value for the FID (1 = screen). |
---|
| 26 | |
---|
| 27 | if ~ischar(FID) |
---|
| 28 | error('If only two parameters are given the first must be a format string.'); |
---|
| 29 | end |
---|
| 30 | |
---|
| 31 | A = format; |
---|
| 32 | format = FID; |
---|
| 33 | fid = 1; |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | N = prod(size(A)); % The number of quaternions to be output. |
---|
| 37 | |
---|
| 38 | % Output is done from a real array R using the standard Matlab fprintf. To construct |
---|
| 39 | % R we have to interleave the components of the quaternion array. |
---|
| 40 | |
---|
| 41 | A = A.'; |
---|
| 42 | |
---|
| 43 | if ispure(A) |
---|
| 44 | N = N .* 3; |
---|
| 45 | R(1 : 3 : N - 2) = x(A); |
---|
| 46 | R(2 : 3 : N - 1) = y(A); |
---|
| 47 | R(3 : 3 : N ) = z(A); |
---|
| 48 | count = fprintf(FID, [ format ' ' format ' ' format '\n'], R); |
---|
| 49 | else |
---|
| 50 | N = N .* 4; |
---|
| 51 | R(1 : 4 : N - 3) = s(A); |
---|
| 52 | R(2 : 4 : N - 2) = x(A); |
---|
| 53 | R(3 : 4 : N - 1) = y(A); |
---|
| 54 | R(4 : 4 : N ) = z(A); |
---|
| 55 | count = fprintf(FID, [format ' ' format ' ' format ' ' format '\n'], R); |
---|
| 56 | end |
---|