From c0420894bef9598f267ea7b7180c42e495f5dbe9 Mon Sep 17 00:00:00 2001 From: Curt Corum <1796102+curtcorum@users.noreply.github.com> Date: Sun, 22 Aug 2021 20:15:18 -0500 Subject: [PATCH] Update readNPY.m modifications from: https://github.com/kwikteam/npy-matlab/issues/9 --- npy-matlab/readNPY.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/npy-matlab/readNPY.m b/npy-matlab/readNPY.m index 9095d00..c79c16f 100644 --- a/npy-matlab/readNPY.m +++ b/npy-matlab/readNPY.m @@ -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));