fnm = 'subject42_t1w_p4.rawb'; dim = [256 256 181]; mat = [1 0 0 -128.75; 0 1 0 -146.75; 0 0 1 -73.25; 0 0 0 1]; fid = fopen(fnm); data = fread(fid, prod(dim), 'uint8'); img = reshape(data, dim); V = struct('fname', 'bw20.img',... 'dim', dim,... 'mat', mat,... 'pinfo', [1;0;0],... 'dt', [spm_type('uint8') spm_platform('BigEnd')],... 'n', [1 1]... ); spm_write_vol(V, img);