You need to consider where the coordinates of the voxels (i,j,k) should be within a mm coordinate system (x,y,z). Doing this involves figuring out a 4x4 matrix M, such that x = m11*i + m12*j + m13*k + m14 y = m21*i + m22*j + m23*k + m24 z = m31*i + m32*j + m33*k + m34 m41 = m42 = m43 = 0 m44 = 1 Once you have figured out this matrix, you can create an image from data by: dim = size(data); Nii = nifti; Nii.dat = file_array('filename.nii',dim, 'float32',352,1,0); Nii.mat = M; Nii.mat0 = M; Nii.descrip = 'My Image'; create(Nii); Nii.dat(:,:,:) = data; Best regards, -John On 18 November 2014 11:20, Janki Mehta <[log in to unmask]> wrote: > Hi, > > I have a 3D matrix in MATLAB which I need to convert to NIfTI or ANALYZE > format so as to view it in SPM8. For this I am using "Tools for NIfTI and > ANALYZE image by Jimmy Shen" available on > http://in.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image. > My problem is once I convert this 3D matrix to ANALYZE format using > make_ana command, I get the brain volume that is rotated/flipped w.r.t the > original volume. > HOw can I resolve this? > NOTE: co-registering this to original brain volume did not help, the > result was still flipped. > > Thanks, > > Janki >