source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/qtfm/@quaternion/write.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.6 KB
Line 
1function write(filename, format, a)
2% WRITE    Output a quaternion array to a text file.
3%
4% write(filename, format, a)
5%
6% This function writes a text file which is designed to be easily
7% read into other software, such as Maple, Mathematica, etc.  The
8% first line of the file contains two integer values giving the
9% number of rows and columns in the file.  The quaternion values
10% then follow in raster order, that is with the column index varying
11% most rapidly. Each quaternion value occupies one line in the file,
12% and consists of four floating-point values, separated by spaces.
13%
14% The format parameter may be omitted, in which case a default is
15% assumed which outputs sufficient digits to represent double values
16% with no loss of accuracy. Otherwise the format is a string (see the
17% standard Matlab function fprintf for details).
18%
19% If the parameter a is a pure quaternion, only three components are
20% written per quaternion.
21
22% Copyright © 2005 Stephen J. Sangwine and Nicolas Le Bihan.
23% See the file : Copyright.m for further details.
24
25error(nargchk(2, 3, nargin)), error(nargoutchk(0, 0, nargout))
26
27if nargin == 2
28   
29    % Only two parameters have been supplied.  The missing one must
30    % be the format, since the other two cannot be omitted. Shuffle
31    % the parameters, and supply the default value for the format.
32
33    a      = format;
34    format = '%+24.16e';   
35end
36
37[r, c] = size(a);
38
39fid = fopen(filename, 'w');
40
41fprintf(fid, '%8u %8u\n', r, c);
42fprintf(fid, format, a);
43fprintf(fid, '\n'); % For some reason the last \n gets omitted in the previous line.
44
45if fclose(fid)
46    error('The file was not written successfully.');
47end
Note: See TracBrowser for help on using the repository browser.