This works for me
function s = load_track(file_name_track)
% function s = load_track(file_name_track)
% This function read the structure of the track from file
fid = fopen(file_name_track, 'r');
if (fid == -1)
error(['File to open does not exist: ' file_name_track]);
end
try
s.ID = fread(fid, 6, 'uint8');
s.dim = fread(fid, 3, 'int16');
s.resol = fread(fid, 3, 'float32');
s.origin = fread(fid, 3, 'float32');
s.n_scalars = fread(fid, 1, 'int16');
s.scalar_name = fread(fid, 200, 'uint8');
s.n_properties = fread(fid, 1, 'int16');
s.property_name = fread(fid, 200, 'uint8');
s.vox_to_ras = reshape(fread(fid, 16, 'float32'), 4, 4);
s.reserved = fread(fid, 508-64, 'uint8');
s.voxelorder = fread(fid, 4, 'uint8');
s.pad1 = fread(fid, 4, 'uint8');
s.img_ori_pat = fread(fid, 6, 'float32');
s.pad2 = fread(fid, 2, 'uint8');
s.invert_x = fread(fid, 1, 'uint8');
s.invert_y = fread(fid, 1, 'uint8');
s.invert_z = fread(fid, 1, 'uint8');
s.swap_xy = fread(fid, 1, 'uint8');
s.swap_yz = fread(fid, 1, 'uint8');
s.swap_zx = fread(fid, 1, 'uint8');
s.n_track = fread(fid, 1, 'int32');
s.version = fread(fid, 1, 'int32');
s.hdr_size = fread(fid, 1, 'int32');
for c_track = 1:s.n_track
% Track Data type Bytes Comment
% Track #1 int 4 Number of points in this track, as m.
% float (3+n_s)*4 Track Point #1. Contains 3 plus n_s float numbers. First 3 float numbers are the x/y/z coordinate of this track point, followed by n_s float numbers representing each of its scalars.
% float (3+n_s)*4 Track Point #2. Same as above.
% … … …
% float (3+n_s)*4 Track Point #m. Same as above.
% float n_p*4 n_p float numbers representing each of the properties of this track.
% Track #n Same as above.
% n is number of points in the track
n = fread(fid, 1, 'int32');
track = zeros(n, 3 + s.n_scalars);
for c = 1:n
track(c,:) = fread(fid, size(track,2), 'float32');
end
% Save the track and scalars
s.track{c_track} = track(:,1:3);
s.track_scalars{c_track} = track(:,4:end);
% Read the properties
s.track_properties{c_track} = fread(fid, s.n_properties, 'float32');
end
fclose(fid);
catch me
fclose(fid);
rethrow(me);
end