Skip to content

Commit

Permalink
Update readNPY.m
Browse files Browse the repository at this point in the history
modifications from:
kwikteam#9
  • Loading branch information
curtcorum authored Aug 23, 2021
1 parent e532dfb commit c042089
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion npy-matlab/readNPY.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@
[~] = fread(fid, totalHeaderLength, 'uint8');

% read the data
data = fread(fid, prod(shape), [dataType '=>' dataType]);
%data = fread(fid, prod(shape), [dataType '=>' dataType]);
% modifications from https://github.com/kwikteam/npy-matlab/issues/9
if strcmp(dataType, "complex8") == 1
data = fread(fid, prod(shape)*2, 'single=>single');
data = data(1:2:end) + 1j * data(2:2:end);
elseif strcmp(dataType, "complex16") == 1
data = fread(fid, prod(shape)*2, 'double=>double');
data = data(1:2:end) + 1j * data(2:2:end);
else
data = fread(fid, prod(shape), [dataType '=>' dataType]);
end

if length(shape)>1 && ~fortranOrder
data = reshape(data, shape(end:-1:1));
Expand Down

0 comments on commit c042089

Please sign in to comment.