Skip to content

Commit

Permalink
Merge pull request #2810 from lukeje/fix_matlab-write-string-filename
Browse files Browse the repository at this point in the history
Allow filename in write_mrtrix.m to be string or char array
  • Loading branch information
jdtournier authored Feb 19, 2024
2 parents 670e7b0 + eddfd61 commit 325dcc1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions matlab/write_mrtrix.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,23 @@ function write_mrtrix (image, filename)

fprintf (fid, '\nfile: ');

if strcmp(filename(end-3:end), '.mif')
[filepath,basename,ext] = fileparts(filename);
if strcmp(ext, '.mif')
dataoffset = ftell (fid) + 18;
dataoffset = dataoffset + mod((4 - mod(dataoffset, 4)), 4);
s = sprintf ('. %d\nEND\n ', dataoffset);
s = s(1:(dataoffset-ftell(fid)));
fprintf (fid, s);
fclose (fid);
fid = fopen (filename, 'a+', byteorder);
elseif strcmp(filename(end-3:end), '.mih')
datafile = [ filename(1:end-4) '.dat' ];
elseif strcmp(ext, '.mih')
datafile = fullfile(filepath, strcat(basename,'.dat'));
fprintf (fid, '%s 0\nEND\n', datafile);
fclose(fid);
fid = fopen (datafile, 'w', byteorder);
else
fclose(fid);
error('unknown file suffix - aborting');
error('unknown file suffix "%s" - aborting', ext);
end

if isstruct(image)
Expand Down

0 comments on commit 325dcc1

Please sign in to comment.