Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slwritearray
Home > sltoolbox > fileio > slwritearray.m

slwritearray

PURPOSE ^

SLWRITEARRAY Writes an array to an array file

SYNOPSIS ^

function slwritearray(A, filename)

DESCRIPTION ^

SLWRITEARRAY Writes an array to an array file

 $ Syntax $
   - slwritearray(A, filename)
   
 $ Arguments $
   - A:            The array to be written
   - filename:     The filename of the array file

 $ Description $
   - slwritearray(A, filename) writes an array A to the array file.

 $ History $
   - Created by Dahua Lin, on Jul 26th, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slpwcomp_blks SLPWCOMP_BLKS Computes pairwise value matrix
  • slimgsetprep SLIMGSETPREP organizes the images in a MATLAB friendly way
  • slpartitionpca SLPARTITIONPCA Performs Partition-based PCA and saves the models

SOURCE CODE ^

0001 function slwritearray(A, filename)
0002 %SLWRITEARRAY Writes an array to an array file
0003 %
0004 % $ Syntax $
0005 %   - slwritearray(A, filename)
0006 %
0007 % $ Arguments $
0008 %   - A:            The array to be written
0009 %   - filename:     The filename of the array file
0010 %
0011 % $ Description $
0012 %   - slwritearray(A, filename) writes an array A to the array file.
0013 %
0014 % $ History $
0015 %   - Created by Dahua Lin, on Jul 26th, 2006
0016 %
0017 
0018 
0019 value_types = { ...
0020     'double', ...
0021     'single', ...
0022     'logical', ...
0023     'char', ...
0024     'int8', ...
0025     'uint8', ...
0026     'int16', ...
0027     'uint16', ...
0028     'int32', ...
0029     'uint32', ...
0030     'int64', ...
0031     'uint64'};
0032 
0033 
0034 %% open file
0035 
0036 fid = fopen(filename, 'w');
0037 if fid <= 0
0038     error('sltoolbox:filefail', ...
0039         'Fail to open file %s', filename);
0040 end
0041 
0042 %% write header
0043 
0044 % write tag
0045 fwrite(fid, ['arr', 0], 'char');
0046 
0047 % write value type and dimension number
0048 [tf, typeidx] = ismember(class(A), value_types);
0049 if ~tf
0050     error('Unknown type for A: %s', class(A));
0051 end
0052 d = ndims(A);
0053 info = uint8([typeidx, d, 0, 0]);
0054 fwrite(fid, info, 'uint8');
0055 
0056 %% write size
0057 
0058 siz = size(A);
0059 fwrite(fid, uint32(siz), 'uint32');
0060 
0061 %% write data
0062 
0063 fwrite(fid, A, class(A));
0064 
0065 %% close file
0066 
0067 fclose(fid);
0068 
0069 
0070 
0071 
0072 
0073

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com