Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt
Created July 10, 2016 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasaarholt/85269e69d3b9f9e4684dd8c5b86b34fc to your computer and use it in GitHub Desktop.
Save thomasaarholt/85269e69d3b9f9e4684dd8c5b86b34fc to your computer and use it in GitHub Desktop.
Matlab code to read bytes from a NanoSIMS image file
function [out,h] = read_bytes(fid, location, num_bytes, ttype, reverse_bytes, b8)
fseek(fid,location,'bof');
h=fread(fid,num_bytes,ttype);
if reverse_bytes
% when data have been stored under Windows, the bytes are reversed
h=h(end:-1:1);
end;
hmax = [255*ones(1,num_bytes-1) 256];
if strcmp(ttype, 'uint8')
out=h(1);
maxv=hmax(1);
for ii=2:num_bytes
out = out*b8 + h(ii);
maxv = maxv*b8 + hmax(ii);
end;
if h(1)==255
out = out-maxv;
end;
elseif strcmp(ttype, 'char')
out = char(h');
else
out = h;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment