Dear Pavel,
if you have V and XYZ, you still need some data. If you've got this data, you could use code like this:
% get sample volume header
V = spm_vol(...);
% set new filename
V.fname = '/my/new/file.nii';
% modify other header data (e.g. datatype V.dt, scaling V.pinfo) if necessary
% if XYZ is in mm, convert to voxels
XYZ = V.mat\[XYZ;ones(1,size(XYZ,2))];
% convert into linear index
XYZind = sub2ind(V.dim, XYZvx(1,:),XYZvx(2,:),XYZvx(3,:));
% create zero-filled data array
Y = zeros(V.dim);
% fill data points from XYZ, your_data could be a single constant or a data vector with one entry for each voxel of interest
Y(XYZind) = your_data;
% write volume
spm_write_vol(V,Y);
Best,
Volkmar
|