Easier to read data via:
P=spm_select(1,'nifti');
Nii=nifti(P);
X=Nii.dat(:,:,:);

or if you want time series data, then you can do:
P=spm_select(Inf,'nifti');
Nii=nifti(P);
FA=cat(4,Nii.dat);
x=squeeze(FA(20,20,20,:));

Best regards,
-John




On 29 May 2013 04:06, MCLAREN, Donald <[log in to unmask]> wrote:
Attached are two alternatives.

READING DATA in SPM:
hdr=spm_vol('filename')
img=spm_read_vols(hdr);

READING DATA in with openIMG:
[img hdr]=openIMG('filename')

==========
WRITING DATA in SPM:
hdr(1).fname='newfilename'
for ii=1:numel(hdr)
  hdr.n(1)=ii;
  spm_write_vol(hdr(1),img(:,:,:,ii))
end

WRITING DATA with writeIMG:
writeIMG(hdr,img,'newfilename')

Best Regards, Donald McLaren
=================
D.G. McLaren, Ph.D.
Research Fellow, Department of Neurology, Massachusetts General Hospital and
Harvard Medical School
Postdoctoral Research Fellow, GRECC, Bedford VA
Website: http://www.martinos.org/~mclaren
Office: (773) 406-2464
=====================
This e-mail contains CONFIDENTIAL INFORMATION which may contain PROTECTED
HEALTHCARE INFORMATION and may also be LEGALLY PRIVILEGED and which is
intended only for the use of the individual or entity named above. If the
reader of the e-mail is not the intended recipient or the employee or agent
responsible for delivering it to the intended recipient, you are hereby
notified that you are in possession of confidential and privileged
information. Any unauthorized use, disclosure, copying or the taking of any
action in reliance on the contents of this information is strictly
prohibited and may be unlawful. If you have received this e-mail
unintentionally, please immediately notify the sender via telephone at (773)
406-2464 or email.


On Sat, May 18, 2013 at 2:15 AM, Torben Lund <[log in to unmask]> wrote:
The reason could be that spm_read_vols (plural) can read multiple volumes into a 4D matrix, whereas spm_write_vol can only write a single volume 3D or 2D. 

Best
Torben





Torben Ellegaard Lund
Associate Professor, PhD
Center of Functionally Integrative Neuroscience (CFIN)
Aarhus University
Aarhus University Hospital
Building 10G, 5th floor, room 31
Noerrebrogade 44
8000 Aarhus C
Denmark
Phone: +45 7846 4380
Fax: +45 7846 4400
http://www.cfin.au.dk
[log in to unmask]



Den Uge:20 18/05/2013 kl. 05.02 skrev Tony Jiang <[log in to unmask]>:

You can write a wrapper easily to do that.
I am sure there might be good reason behind it not doing that
 
-----------------------------------------------
Tony Jiang, Ph.D.
Human Performance  & Engineering Laboratory
Kessler Foundation Research Center
1199 Pleasant Valley Way
West Orange, NJ 07052
 
 
From: SPM (Statistical Parametric Mapping) [mailto:[log in to unmask]] On Behalf Of Anna Jafarpour
Sent: Friday, May 17, 2013 9:04 AM
To: [log in to unmask]
Subject: [SPM] nothing urgent ... just for making spm12 prettier
 
Functions 

spm_write_vol

and
spm_read_vols

can they both be _vols or _vol  please?


Kessler Foundation Signature

Kessler Foundation Facebook Page Kessler Foundation You Tube Kessler Foundation Research Twitter Page

The information in this transmission is intended for official use of the Kessler Foundation. It is intended for the exclusive use of the persons or entities to which it is addressed. If you are not an intended recipient or the employee or agent responsible for delivering this transmission to an intended recipient, be aware that any disclosure, dissemination, distribution or copying of this communication, or the use of its contents, is strictly prohibited. If you received this transmission in error, please notify the sender by return e-mail and delete the material from any computer.   ­­