fnm = 'subject42_crisp_v.rawb'; dim = [362 434 362]; mat = [0.5 0 0 -90.75; 0 0.5 0 -126.75; 0 0 0.5 -72.75; 0 0 0 1]; fid = fopen(fnm); data = fread(fid, prod(dim), 'uint8'); img = reshape(data, dim); V = struct('fname', 'bw20_seg.img',... 'dim', dim,... 'mat', mat,... 'pinfo', [1;0;0],... 'dt', [spm_type('uint8') spm_platform('BigEnd')],... 'n', [1 1]... ); spm_write_vol(V, img);