% NPY-MATLAB constructNPYheader function. Copied from https://github.com/kwikteam/npy-matlab function header = constructNPYheader(dataType, shape, varargin) if ~isempty(varargin) fortranOrder = varargin{1}; % must be true/false littleEndian = varargin{2}; % must be true/false else fortranOrder = true; littleEndian = true; end dtypesMatlab = {'uint8','uint16','uint32','uint64','int8','int16','int32','int64','single','double', 'logical'}; dtypesNPY = {'u1', 'u2', 'u4', 'u8', 'i1', 'i2', 'i4', 'i8', 'f4', 'f8', 'b1'}; magicString = uint8([147 78 85 77 80 89]); %x93NUMPY majorVersion = uint8(1); minorVersion = uint8(0); % build the dict specifying data type, array order, endianness, and % shape dictString = '{''descr'': '''; if littleEndian dictString = [dictString '<']; else dictString = [dictString '>']; end dictString = [dictString dtypesNPY{strcmp(dtypesMatlab,dataType)} ''', ']; dictString = [dictString '''fortran_order'': ']; if fortranOrder dictString = [dictString 'True, ']; else dictString = [dictString 'False, ']; end dictString = [dictString '''shape'': (']; % if length(shape)==1 && shape==1 % % else % for s = 1:length(shape) % if s==length(shape) && shape(s)==1 % % else % dictString = [dictString num2str(shape(s))]; % if length(shape)>1 && s+1==length(shape) && shape(s+1)==1 % dictString = [dictString ',']; % elseif length(shape)>1 && s