FOUND IT! 
The problem was with the startup.m file (nice catch dough). I had a change directory line (cd users/maryam/programs) in the end of the startup.m file that made matlab change directory to another directory that did not have the textfile necessary for the mcparams2extreg. I took that line out and now the preproc-sess works.

Thanks for all the help. 
Maryam

On Thu, Apr 28, 2011 at 5:32 PM, Douglas Greve <greve@nmr.mgh.harvard.edu> wrote:
That first one should have worked (or at least given you some other error). That error indicates that it can't find mcp2x.m. But it's in the same directory that you are running matlab from, right? I thought of something else to check. Can you send me your ~/matlab/startup.m file?

doug


On 4/28/11 3:51 PM, Maryam Vaziri Pashkam wrote:
Hi,

I tried  " matlab -r mcp2x" and " matlab -r mcp2x.m" in both cased I get an error that "undefined function or variable mcp2x. I tried cat mcp2x.m | matlab, and the program runs and gives the exact same error as before when I ran mcparams2extreg from within terminal (see bellow). It looks like an error that occurs when you are in the wrong directory in matlab and you are calling a file from another directory which does not make sense as the fmc files are created in the correct path. 

Maryam

>> >> >> >> >> >> >> >> ??? Error using ==> textread at 167
File not found.
 
>> ??? Undefined variable mc.
 
>> ??? Undefined function or variable 'mc'.
 
>> ??? Undefined function or variable 'ntrs'.
 
>> >> ??? Undefined variable mc.
 
>> >> ??? Undefined function or variable 'ntrs'.
 
>> ??? Undefined function or variable 'x'.
 
>> >> >> ??? Undefined function or variable 'x2'.
 
>> >> >> >> >> >> >> >> >> >> ??? Reference to non-existent field 'vol'.
 
>> >> ??? Reference to non-existent field 'vol'.

Error in ==> MRIwrite at 70
  bmri.voldim = [size(mri.vol,1) size(mri.vol,2) size(mri.vol,3)];




On Thu, Apr 28, 2011 at 8:52 AM, <greve@nmr.mgh.harvard.edu> wrote:
I'm not sure where to proceed next. I can't create the error on my mac, so
it must be something about your version of matlab/macos. Let's go back to
trying  the matlab -r command. Is this what you did:

cd session/bold
mcparams2extreg -extreg junk.txt -mcfile RRR/fmc.mcdat -nkeep 6 -monly
mcp2x.m
matlab -r mcp2x

It should not have generated the same error as when using mcp2x.m.

Can you also try
cat mcp2x.m | matlab

doug


> HI Doug,
>
> Did you get the file I sent you?
> Any new idea about how I can fix the problem?
>
> Maryam
>
> On Tue, Apr 26, 2011 at 5:25 AM, Douglas Greve
> <greve@nmr.mgh.harvard.edu>wrote:
>
>>
>> The file will be found in $FREESURFER_HOME/fsfast/bin/mcparams2extreg,
>> but
>> until we figure out how to run matlab in a way that does not crash, it
>> will
>> not do any good to edit this file. Actually, can you send me your
>> version of
>> mcparams2extreg? I ran your matlab file on my mac by catting it to
>> matlab,
>> but it failed with I tried to run it with -r (don't know why).
>>
>> doug
>>
>> On 4/25/11 4:41 PM, Maryam Vaziri Pashkam wrote:
>>
>> Here is the m file.
>>
>>  I have two versions of Matlab: R2008a, R2009b. The one that freesurfer
>> runs when calling matlab codes in 2009b.
>>
>>  Sorry I am not sure what I should copy to my home directory and edit. I
>> thought the line you asked me to change was in the   mcparams2extreg
>> file
>> which I don't know where it is. Could you explain a bit more?
>>
>>  Maryam
>>
>>
>>
>> On Mon, Apr 25, 2011 at 4:34 PM, Douglas Greve
>> <greve@nmr.mgh.harvard.edu>wrote:
>>
>>>  Can you send me the matlab file? And what version of matlab are you
>>> running? On the mac, you'll probably have to copy it to your home
>>> directly,
>>> edit it, then copy it back. When you copy it back, you'll have to sudo
>>> to
>>> get administrator privileges.
>>>
>>> doug
>>>
>>>
>>> On 4/25/11 4:26 PM, Maryam Vaziri Pashkam wrote:
>>>
>>> There is an error:
>>>
>>>  ??? Error: Unexpected MATLAB operator when I run matlab -r
>>> matlabfile.m
>>> I wanted to change the mcparams2extreg to see if it works but I don't
>>> know
>>> how to change it and where it is located.
>>>
>>>  Maryam
>>>
>>> On Mon, Apr 25, 2011 at 3:22 PM, Douglas Greve
>>> <greve@nmr.mgh.harvard.edu
>>> > wrote:
>>>
>>>>
>>>> Yea, I vaguely remember this problem with 4.5 and the macs. Try
>>>> running
>>>> this from a terminal (not from matlab):
>>>>
>>>> matlab -r matlabfile.m
>>>>
>>>> where matlabfile.m is the file created with -monly. If this works you
>>>> can
>>>> change the call to matlab from mcparams2extreg from
>>>>
>>>> cat $MLF | $MATLAB -display iconic | tee -a $LF
>>>>
>>>> to
>>>>
>>>> $MATLAB -r $MLF -display iconic | tee -a $LF
>>>>
>>>> doug
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 4/25/11 2:49 PM, Maryam Vaziri Pashkam wrote:
>>>>
>>>> Hi Dough,
>>>>
>>>>  The generated matlab programs works from within matlab and generates
>>>> mcextreg.bhdr and mcextreg_000.bfloat and mcextreg_000.hdr.
>>>>
>>>>  It seems that there is a problem calling matlab from terminal? any
>>>> idea
>>>> how I can fix this? I have two versions on Matlab on my computer.
>>>> Could this
>>>> be a source of the problem? I checked the program in both matlabs and
>>>> it
>>>> works when run from inside Matlab.
>>>>
>>>>  Maryam
>>>>
>>>>
>>>> On Mon, Apr 25, 2011 at 4:32 AM, Douglas Greve <
>>>> greve@nmr.mgh.harvard.edu> wrote:
>>>>
>>>>>  Try running mcparams2extreg with the -monly option to create a
>>>>> matlab
>>>>> file. Then run that matlab file from inside matlab. If that fails in
>>>>> the
>>>>> same way, send me the matlab file.
>>>>>
>>>>> doug
>>>>>
>>>>>
>>>>> On 4/25/11 4:02 AM, Maryam Vaziri Pashkam wrote:
>>>>>
>>>>> Hi Dough,
>>>>>
>>>>> I have attached the log file. It does not give any extra information.
>>>>> I
>>>>> ran the command you told me and gave me the exact same errors. It
>>>>> looks like
>>>>> there is a problem with that command and reading of the fmc.mcdat
>>>>> file. I
>>>>> have also attached the fmc.mcdat file from run 6.
>>>>> Any other idea?
>>>>>
>>>>>  Thanks,
>>>>> Maryam
>>>>>
>>>>> On Mon, Apr 25, 2011 at 3:44 AM, <
>>>>> freesurfer-request@nmr.mgh.harvard.edu> wrote:
>>>>>
>>>>>> Send Freesurfer mailing list submissions to
>>>>>>        freesurfer@nmr.mgh.harvard.edu
>>>>>>
>>>>>> To subscribe or unsubscribe via the World Wide Web, visit
>>>>>>        https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
>>>>>> or, via email, send a message with subject or body 'help' to
>>>>>>        freesurfer-request@nmr.mgh.harvard.edu
>>>>>>
>>>>>> You can reach the person managing the list at
>>>>>>        freesurfer-owner@nmr.mgh.harvard.edu
>>>>>>
>>>>>> When replying, please edit your Subject line so it is more specific
>>>>>> than "Re: Contents of Freesurfer digest..."
>>>>>>
>>>>>>
>>>>>> Today's Topics:
>>>>>>
>>>>>>   1. Fwd: error with motion correction (Maryam Vaziri Pashkam)
>>>>>>   2. Re: Fwd: error with motion correction (Douglas Greve)
>>>>>>
>>>>>>
>>>>>> ----------------------------------------------------------------------
>>>>>>
>>>>>> Message: 1
>>>>>> Date: Sun, 24 Apr 2011 21:01:43 -0400
>>>>>> From: Maryam Vaziri Pashkam <mvaziri.p@gmail.com>
>>>>>> Subject: [Freesurfer] Fwd: error with motion correction
>>>>>> To: freesurfer@nmr.mgh.harvard.edu
>>>>>> Message-ID: <BANLkTikkaJvqP5bxVD5e2moWQvwBrev9iA@mail.gmail.com>
>>>>>> Content-Type: text/plain; charset="iso-8859-1"
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am running into trouble with motion correction on my Mac and
>>>>>> freesurfer
>>>>>> 4.5.
>>>>>> Originally I ran preproc-sess and got an error from mc-sess in the
>>>>>> part
>>>>>> (i
>>>>>> think) that runs the mcextreg. I ran mc-sess and the same error
>>>>>> happened (I
>>>>>> have copy pasted the log bellow).
>>>>>> It seems like the matlab program that runs mcparams2extreg cannot
>>>>>> read
>>>>>> the
>>>>>> fmc.mcdat file. when I did textread('fmc.mcdat') in matlab, I could
>>>>>> open the
>>>>>> file and it looked perfectly fine to me with the correct number of
>>>>>> TR's.
>>>>>> Any idea where the problem might be?
>>>>>>
>>>>>> Maryam
>>>>>>
>>>>>> preproc-sess -nosmooth -i f -sf sessid -df sessdir
>>>>>> --------------------------------------------------------------
>>>>>> preproc-sess logfile is log/preproc-sess.log
>>>>>> --------------------------------------------------------------
>>>>>> instem   f
>>>>>> mc   1     f fmc
>>>>>> stc  0     fmc
>>>>>> sm   0
>>>>>> mask 1   brain
>>>>>> 110419_xu_PDM1_02_PDM MC -----------------------------
>>>>>> Sun Apr 24 20:42:29 EDT 2011
>>>>>> /Users/maryam/mri-space/studies/PDM1/PDM1
>>>>>> mc-sess -fstem f -fmcstem fmc -s 110419_xu_PDM1_02_PDM -d
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata -fsd bold -new
>>>>>> -update
>>>>>> -no-inorm
>>>>>> ----------------------------------------
>>>>>> Logfile is
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/PDM1/log/mc-110419_xu_PDM1_02_PDM-bold.log
>>>>>> -------------------------------------------
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM
>>>>>> RunList: 005 006 007 008 <005%20006%20007%20008> 011 012 013 014
>>>>>> Targ Stem is 005/f
>>>>>> Update not needed
>>>>>> -rw-r--r--  1 maryam  staff  129203552 Apr 24 20:12 005/fmc.nii
>>>>>> -rw-r--r--  1 maryam  staff   64601952 Apr 24 19:12 005/f.nii
>>>>>>  ------- ************************** -----------
>>>>>>  ------- Motion Correcting Run 006 -----------
>>>>>>  ------- ************************** -----------
>>>>>> sess = 110419_xu_PDM1_02_PDM
>>>>>> Sun Apr 24 20:42:30 EDT 2011
>>>>>> mc-afni2 --i 006/f.nii --t 005/f.nii --frame 0 --o 006/fmc.nii
>>>>>> --mcdat
>>>>>> 006/fmc.mcdat
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> mri_info --nframes --o /tmp/mriinfo.2758 005/f.nii
>>>>>> log file is 006/fmc.nii.mclog
>>>>>> mcdat file is 006/fmc.mcdat
>>>>>> tmp dir is 006/tmp.mc-afni2.2758
>>>>>> #@# --------------------------------
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> mri_convert 005/f.nii 006/tmp.mc-afni2.2758/tempvol.nii.gz --nskip 0
>>>>>> --ndrop
>>>>>> 205 -odt float
>>>>>> mri_convert 005/f.nii 006/tmp.mc-afni2.2758/tempvol.nii.gz --nskip 0
>>>>>> --ndrop
>>>>>> 205 -odt float
>>>>>> nskip = 0
>>>>>> ndrop = 205
>>>>>> $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> reading from 005/f.nii...
>>>>>> TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> changing data type from 4 to 3 (noscale = 0)...
>>>>>> Dropping last 205 frames
>>>>>> writing to 006/tmp.mc-afni2.2758/tempvol.nii.gz...
>>>>>> #@# --------------------------------
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> mri_convert 006/f.nii 006/tmp.mc-afni2.2758/invol.nii.gz -odt float
>>>>>> mri_convert 006/f.nii 006/tmp.mc-afni2.2758/invol.nii.gz -odt float
>>>>>> $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> reading from 006/f.nii...
>>>>>> TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> changing data type from 4 to 3 (noscale = 0)...
>>>>>> writing to 006/tmp.mc-afni2.2758/invol.nii.gz...
>>>>>> #@# --------------------------------
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> 3dvolreg -verbose -dfile 006/fmc.mcdat -base
>>>>>> 006/tmp.mc-afni2.2758/tempvol.nii.gz -prefix
>>>>>> 006/tmp.mc-afni2.2758/outvol.nii.gz
>>>>>> 006/tmp.mc-afni2.2758/invol.nii.gz
>>>>>> ++ 3dvolreg: AFNI version=AFNI_2008_02_01_1144 (Jul  3 2008)
>>>>>> [32-bit]
>>>>>> ++ Authored by: RW Cox
>>>>>> *+ WARNING:   If you are performing spatial transformations on an
>>>>>> oblique
>>>>>> dset,
>>>>>>  such as 006/tmp.mc-afni2.2758/tempvol.nii.gz,
>>>>>>  or viewing/combining it with volumes of differing obliquity,
>>>>>>  you should consider running:
>>>>>>     3dWarp -deoblique
>>>>>>  on this and  other oblique datasets in the same session.
>>>>>>  See 3dWarp -help for details.
>>>>>> ++ Oblique dataset:006/tmp.mc-afni2.2758/tempvol.nii.gz is 10.399981
>>>>>> degrees
>>>>>> from plumb.
>>>>>> ++ Reading in base dataset 006/tmp.mc-afni2.2758/tempvol.nii.gz
>>>>>> ++ Oblique dataset:006/tmp.mc-afni2.2758/invol.nii.gz is 10.399981
>>>>>> degrees
>>>>>> from plumb.
>>>>>> ++ Reading input dataset 006/tmp.mc-afni2.2758/invol.nii.gz
>>>>>> ++ Edging: x=4 y=4 z=2
>>>>>> ++ Creating mask for -maxdisp
>>>>>>  + Automask has 57667 voxels
>>>>>>  + 10333 voxels left in -maxdisp mask after erosion
>>>>>> ++ Initializing alignment base
>>>>>> ++ Starting final pass on 206 sub-bricks:
>>>>>>
>>>>>> 0..1..2..3..4..5..6..7..8..9..10..11..12..13..14..15..16..17..18..19..20..21..22..23..24..25..26..27..28..29..30..31..32..33..34..35..36..37..38..39..40..41..42..43..44..45..46..47..48..49..50..51..52..53..54..55..56..57..58..59..60..61..62..63..64..65..66..67..68..69..70..71..72..73..74..75..76..77..78..79..80..81..82..83..84..85..86..87..88..89..90..91..92..93..94..95..96..97..98..99..100..101..102..103..104..105..106..107..108..109..110..111..112..113..114..115..116..117..118..119..120..121..122..123..124..125..126..127..128..129..130..131..132..133..134..135..136..137..138..139..140..141..142..143..144..145..146..147..148..149..150..151..152..153..154..155..156..157..158..159..160..161..162..163..164..165..166..167..168..169..170..171..172..173..174..175..176..177..178..179..180..181..182..183..184..185..186..187..188..189..190..191..192..193..194..195..196..197..198..199..200..201..202..203..204..205..
>>>>>> ++ CPU time for realignment=16.6 s  [=0.0808 s/sub-brick]
>>>>>> ++ Min : roll=-0.008  pitch=-0.103  yaw=-0.096  dS=+0.255  dL=-0.019
>>>>>>  dP=-0.151
>>>>>> ++ Mean: roll=+0.031  pitch=-0.011  yaw=-0.045  dS=+0.619  dL=+0.037
>>>>>>  dP=-0.055
>>>>>> ++ Max : roll=+0.060  pitch=+0.112  yaw=-0.010  dS=+0.693  dL=+0.075
>>>>>>  dP=+0.015
>>>>>> ++ Max displacements (mm) for each sub-brick:
>>>>>>  0.49 0.65 0.63 0.74 0.69 0.75 0.71 0.77 0.70 0.76 0.67 0.77 0.72
>>>>>> 0.73
>>>>>> 0.66
>>>>>> 0.67 0.67 0.67 0.69 0.70 0.72 0.66 0.71 0.68 0.72 0.67 0.73 0.68
>>>>>> 0.73
>>>>>> 0.66
>>>>>> 0.73 0.66 0.70 0.64 0.72 0.69 0.71 0.71 0.72 0.66 0.66 0.67 0.72
>>>>>> 0.70
>>>>>> 0.71
>>>>>> 0.72 0.71 0.69 0.72 0.72 0.71 0.72 0.72 0.69 0.71 0.74 0.73 0.69
>>>>>> 0.72
>>>>>> 0.72
>>>>>> 0.76 0.76 0.79 0.73 0.75 0.74 0.75 0.75 0.71 0.74 0.67 0.72 0.65
>>>>>> 0.72
>>>>>> 0.65
>>>>>> 0.69 0.69 0.65 0.68 0.64 0.72 0.67 0.67 0.68 0.69 0.65 0.73 0.67
>>>>>> 0.71
>>>>>> 0.69
>>>>>> 0.73 0.72 0.76 0.74 0.72 0.66 0.68 0.69 0.69 0.68 0.68 0.70 0.73
>>>>>> 0.70
>>>>>> 0.73
>>>>>> 0.78 0.74 0.73 0.75 0.74 0.72 0.74 0.63 0.66 0.68 0.74 0.72 0.74
>>>>>> 0.79
>>>>>> 0.74
>>>>>> 0.74 0.76 0.79 0.79 0.74 0.76 0.70 0.75 0.72 0.78 0.74 0.78 0.76
>>>>>> 0.80
>>>>>> 0.76
>>>>>> 0.79 0.77 0.76 0.76 0.75 0.73 0.80 0.78 0.81 0.78 0.84 0.76 0.79
>>>>>> 0.77
>>>>>> 0.79
>>>>>> 0.76 0.83 0.77 0.79 0.77 0.84 0.76 0.80 0.77 0.81 0.72 0.79 0.74
>>>>>> 0.80
>>>>>> 0.77
>>>>>> 0.83 0.81 0.82 0.76 0.81 0.75 0.78 0.74 0.75 0.71 0.75 0.73 0.77
>>>>>> 0.77
>>>>>> 0.80
>>>>>> 0.77 0.80 0.75 0.73 0.77 0.72 0.76 0.72 0.76 0.72 0.72 0.69 0.66
>>>>>> 0.68
>>>>>> 0.65
>>>>>> 0.68 0.64 0.70 0.62 0.70 0.62 0.69 0.67 0.74 0.75 0.74
>>>>>> ++ Max displacement in automask = 0.84 (mm) at sub-brick 145
>>>>>> ++ Wrote dataset to disk in 006/tmp.mc-afni2.2758/outvol.nii.gz
>>>>>> #@# --------------------------------
>>>>>>
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> mri_convert 006/tmp.mc-afni2.2758/outvol.nii.gz 006/fmc.nii
>>>>>> --in_like
>>>>>> 005/f.nii
>>>>>> mri_convert 006/tmp.mc-afni2.2758/outvol.nii.gz 006/fmc.nii
>>>>>> --in_like
>>>>>> 005/f.nii
>>>>>> reading info from 005/f.nii...
>>>>>> $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> reading from 006/tmp.mc-afni2.2758/outvol.nii.gz...
>>>>>> TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> writing to 006/fmc.nii...
>>>>>> ... cleaning up ....
>>>>>> Sun Apr 24 20:43:59 EDT 2011
>>>>>> mc-afni2 done
>>>>>> INFO: Making external regressor from mc params
>>>>>> mcparams2extreg -mcfile 006/fmc.mcdat -northog 6 -extreg
>>>>>> 006/mcextreg
>>>>>> Logfile is 006/mcparams2extreg.log
>>>>>> ----------- Matlab file --------------
>>>>>>  mcfile = '006/fmc.mcdat';
>>>>>>  extreg = '006/mcextreg';
>>>>>>  nkeep     = [];
>>>>>>  northog   = [6];
>>>>>>  pctorthog = [];
>>>>>>  monly     = 0;
>>>>>>
>>>>>>  mc = textread(mcfile);
>>>>>>  mc = mc(:,2:7);
>>>>>>  ntrs = size(mc,1);
>>>>>>  if(ntrs < 6)
>>>>>>    fprintf('ERROR: ntrs = %d < 6\n',ntrs);
>>>>>>    if(~monly)
>>>>>>      fprintf('Quiting matlab\n');
>>>>>>      quit;
>>>>>>      fprintf('should not be here\n');
>>>>>>    end
>>>>>>  end
>>>>>>
>>>>>>  if(~isempty(nkeep))
>>>>>>    x = mc(:,1:nkeep);
>>>>>>  elseif(~isempty(northog))
>>>>>>    [u s v] = svd(mc);
>>>>>>    ds = diag(s);
>>>>>>    pct = 100*cumsum(ds)/sum(ds);
>>>>>>    x = u(:,1:northog);
>>>>>>    nkeep = northog;
>>>>>>    fprintf('INFO: northog = %d, pct = %g\n',northog,pct(nkeep));
>>>>>>  else
>>>>>>    [u s v] = svd(mc);
>>>>>>    ds = diag(s);
>>>>>>    pct = 100*cumsum(ds)/sum(ds);
>>>>>>    nkeep = min(find(pct > pctorthog));
>>>>>>    x = u(:,1:nkeep);
>>>>>>    fprintf('INFO: pctorthog = %g, nkeep = %d\n',pctorthog,nkeep);
>>>>>>  end
>>>>>>
>>>>>>  x2 = zeros(1,1,nkeep,ntrs);
>>>>>>  x2(1,1,:,:) = x'; %'
>>>>>>  %fmri_svbvolume(x2,extreg);
>>>>>>
>>>>>>  mri.vol = permute(x2,[1 3 2 4]);
>>>>>>  mri.tr = 0;
>>>>>>  mri.flip_angle = 0;
>>>>>>  mri.te = 0;
>>>>>>  mri.ti = 0;
>>>>>>  mri.vox2ras0 = eye(4);
>>>>>>  mri.xsize = 1;
>>>>>>  mri.ysize = 1;
>>>>>>  mri.zsize = 1;
>>>>>>  mri.volres = [1 1 1];
>>>>>>  mri.volsize = [size(mri.vol,1) size(mri.vol,2) size(mri.vol,3)];
>>>>>>  fname = sprintf('%s.bhdr',extreg);
>>>>>>  MRIwrite(mri,fname);
>>>>>>
>>>>>> quit;
>>>>>>
>>>>>> -----------------------------------
>>>>>> ------------------------------------------
>>>>>> ------- matlab output --------------------
>>>>>> Warning: Unable to open display 'iconic'.  You will not be able to
>>>>>> display
>>>>>> graphics on the screen.
>>>>>>
>>>>>>                            < M A T L A B (R) >
>>>>>>                  Copyright 1984-2009 The MathWorks, Inc.
>>>>>>                 Version 7.9.0.529 (R2009b) 64-bit (maci64)
>>>>>>                              August 12, 2009
>>>>>>
>>>>>>  To get started, type one of these: helpwin, helpdesk, or demo.
>>>>>>  For product information, visit www.mathworks.com.
>>>>>>
>>>>>> >> >> >> >> >> >> >> >> ??? Error using ==> textread at 167
>>>>>> File not found.
>>>>>>
>>>>>> >> ??? Undefined variable mc.
>>>>>>
>>>>>> >> ??? Undefined function or variable 'mc'.
>>>>>>
>>>>>> >> ??? Undefined function or variable 'ntrs'.
>>>>>>
>>>>>> >> >> ??? Undefined function or variable 'mc'.
>>>>>>
>>>>>> >> >> ??? Undefined function or variable 'ntrs'.
>>>>>>
>>>>>> >> ??? Undefined function or variable 'x'.
>>>>>>
>>>>>> >> >> >> ??? Undefined function or variable 'x2'.
>>>>>>
>>>>>> >> >> >> >> >> >> >> >> >> >> ??? Reference to non-existent field
>>>>>> 'vol'.
>>>>>>
>>>>>> >> >> ??? Reference to non-existent field 'vol'.
>>>>>>
>>>>>> Error in ==> MRIwrite at 70
>>>>>>  bmri.voldim = [size(mri.vol,1) size(mri.vol,2) size(mri.vol,3)];
>>>>>>
>>>>>> >> >> ------------------------------------------
>>>>>> ERROR: output not created
>>>>>> ERROR: mc-sess failed
>>>>>> -------------- next part --------------
>>>>>> An HTML attachment was scrubbed...
>>>>>> URL:
>>>>>> http://mail.nmr.mgh.harvard.edu/pipermail/freesurfer/attachments/20110424/7835b719/attachment-0001.html
>>>>>>
>>>>>> ------------------------------
>>>>>>
>>>>>> Message: 2
>>>>>> Date: Mon, 25 Apr 2011 03:43:59 -0400
>>>>>> From: Douglas Greve <greve@nmr.mgh.harvard.edu>
>>>>>> Subject: Re: [Freesurfer] Fwd: error with motion correction
>>>>>> To: freesurfer@nmr.mgh.harvard.edu
>>>>>> Message-ID: <4DB5263F.2060902@nmr.mgh.harvard.edu>
>>>>>> Content-Type: text/plain; charset="iso-8859-1"
>>>>>>
>>>>>> Hi Maryam, I don't know what is going on. Does
>>>>>> 006/mcparams2extreg.log
>>>>>> have anymore information? Can you run
>>>>>>
>>>>>> cd 110419_xu_PDM1_02_PDM/bold
>>>>>> mcparams2extreg -mcfile 006/fmc.mcdat -northog 6 -extreg
>>>>>> 006/mcextreg
>>>>>>
>>>>>> doug
>>>>>>
>>>>>> On 4/24/11 9:01 PM, Maryam Vaziri Pashkam wrote:
>>>>>> >
>>>>>> > Hi,
>>>>>> >
>>>>>> > I am running into trouble with motion correction on my Mac and
>>>>>> > freesurfer 4.5.
>>>>>> > Originally I ran preproc-sess and got an error from mc-sess in the
>>>>>> > part (i think) that runs the mcextreg. I ran mc-sess and the same
>>>>>> > error happened (I have copy pasted the log bellow).
>>>>>> > It seems like the matlab program that runs mcparams2extreg cannot
>>>>>> read
>>>>>> > the fmc.mcdat file. when I did textread('fmc.mcdat') in matlab, I
>>>>>> > could open the file and it looked perfectly fine to me with the
>>>>>> > correct number of TR's.
>>>>>> > Any idea where the problem might be?
>>>>>> >
>>>>>> > Maryam
>>>>>> >
>>>>>> > preproc-sess -nosmooth -i f -sf sessid -df sessdir
>>>>>> > --------------------------------------------------------------
>>>>>> > preproc-sess logfile is log/preproc-sess.log
>>>>>> > --------------------------------------------------------------
>>>>>> > instem   f
>>>>>> > mc   1     f fmc
>>>>>> > stc  0     fmc
>>>>>> > sm   0
>>>>>> > mask 1   brain
>>>>>> > 110419_xu_PDM1_02_PDM MC -----------------------------
>>>>>> > Sun Apr 24 20:42:29 EDT 2011
>>>>>> > /Users/maryam/mri-space/studies/PDM1/PDM1
>>>>>> > mc-sess -fstem f -fmcstem fmc -s 110419_xu_PDM1_02_PDM -d
>>>>>> > /Users/maryam/mri-space/studies/PDM1/unpackdata -fsd bold -new
>>>>>> -update
>>>>>> > -no-inorm
>>>>>> > ----------------------------------------
>>>>>> > Logfile is
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/PDM1/log/mc-110419_xu_PDM1_02_PDM-bold.log
>>>>>> > -------------------------------------------
>>>>>> > /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM
>>>>>> > RunList: 005 006 007 008 011 012 013 014
>>>>>> > Targ Stem is 005/f
>>>>>> > Update not needed
>>>>>> > -rw-r--r--  1 maryam  staff  129203552 Apr 24 20:12 005/fmc.nii
>>>>>> > -rw-r--r--  1 maryam  staff   64601952 Apr 24 19:12 005/f.nii
>>>>>> >   ------- ************************** -----------
>>>>>> >   ------- Motion Correcting Run 006 -----------
>>>>>> >   ------- ************************** -----------
>>>>>> > sess = 110419_xu_PDM1_02_PDM
>>>>>> > Sun Apr 24 20:42:30 EDT 2011
>>>>>> > mc-afni2 --i 006/f.nii --t 005/f.nii --frame 0 --o 006/fmc.nii
>>>>>> --mcdat
>>>>>> > 006/fmc.mcdat
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> > mri_info --nframes --o /tmp/mriinfo.2758 005/f.nii
>>>>>> > log file is 006/fmc.nii.mclog
>>>>>> > mcdat file is 006/fmc.mcdat
>>>>>> > tmp dir is 006/tmp.mc-afni2.2758
>>>>>> > #@# --------------------------------
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> > mri_convert 005/f.nii 006/tmp.mc-afni2.2758/tempvol.nii.gz --nskip
>>>>>> 0
>>>>>> > --ndrop 205 -odt float
>>>>>> > mri_convert 005/f.nii 006/tmp.mc-afni2.2758/tempvol.nii.gz --nskip
>>>>>> 0
>>>>>> > --ndrop 205 -odt float
>>>>>> > nskip = 0
>>>>>> > ndrop = 205
>>>>>> > $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> > reading from 005/f.nii...
>>>>>> > TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> > i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> > j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> > k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> > changing data type from 4 to 3 (noscale = 0)...
>>>>>> > Dropping last 205 frames
>>>>>> > writing to 006/tmp.mc-afni2.2758/tempvol.nii.gz...
>>>>>> > #@# --------------------------------
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> > mri_convert 006/f.nii 006/tmp.mc-afni2.2758/invol.nii.gz -odt
>>>>>> float
>>>>>> > mri_convert 006/f.nii 006/tmp.mc-afni2.2758/invol.nii.gz -odt
>>>>>> float
>>>>>> > $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> > reading from 006/f.nii...
>>>>>> > TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> > i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> > j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> > k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> > changing data type from 4 to 3 (noscale = 0)...
>>>>>> > writing to 006/tmp.mc-afni2.2758/invol.nii.gz...
>>>>>> > #@# --------------------------------
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> > 3dvolreg -verbose -dfile 006/fmc.mcdat -base
>>>>>> > 006/tmp.mc-afni2.2758/tempvol.nii.gz -prefix
>>>>>> > 006/tmp.mc-afni2.2758/outvol.nii.gz
>>>>>> 006/tmp.mc-afni2.2758/invol.nii.gz
>>>>>> > ++ 3dvolreg: AFNI version=AFNI_2008_02_01_1144 (Jul  3 2008)
>>>>>> [32-bit]
>>>>>> > ++ Authored by: RW Cox
>>>>>> > *+ WARNING:   If you are performing spatial transformations on an
>>>>>> > oblique dset,
>>>>>> >   such as 006/tmp.mc-afni2.2758/tempvol.nii.gz,
>>>>>> >   or viewing/combining it with volumes of differing obliquity,
>>>>>> >   you should consider running:
>>>>>> >      3dWarp -deoblique
>>>>>> >   on this and  other oblique datasets in the same session.
>>>>>> >  See 3dWarp -help for details.
>>>>>> > ++ Oblique dataset:006/tmp.mc-afni2.2758/tempvol.nii.gz is
>>>>>> 10.399981
>>>>>> > degrees from plumb.
>>>>>> > ++ Reading in base dataset 006/tmp.mc-afni2.2758/tempvol.nii.gz
>>>>>> > ++ Oblique dataset:006/tmp.mc-afni2.2758/invol.nii.gz is 10.399981
>>>>>> > degrees from plumb.
>>>>>> > ++ Reading input dataset 006/tmp.mc-afni2.2758/invol.nii.gz
>>>>>> > ++ Edging: x=4 y=4 z=2
>>>>>> > ++ Creating mask for -maxdisp
>>>>>> >  + Automask has 57667 voxels
>>>>>> >  + 10333 voxels left in -maxdisp mask after erosion
>>>>>> > ++ Initializing alignment base
>>>>>> > ++ Starting final pass on 206 sub-bricks:
>>>>>> >
>>>>>> 0..1..2..3..4..5..6..7..8..9..10..11..12..13..14..15..16..17..18..19..20..21..22..23..24..25..26..27..28..29..30..31..32..33..34..35..36..37..38..39..40..41..42..43..44..45..46..47..48..49..50..51..52..53..54..55..56..57..58..59..60..61..62..63..64..65..66..67..68..69..70..71..72..73..74..75..76..77..78..79..80..81..82..83..84..85..86..87..88..89..90..91..92..93..94..95..96..97..98..99..100..101..102..103..104..105..106..107..108..109..110..111..112..113..114..115..116..117..118..119..120..121..122..123..124..125..126..127..128..129..130..131..132..133..134..135..136..137..138..139..140..141..142..143..144..145..146..147..148..149..150..151..152..153..154..155..156..157..158..159..160..161..162..163..164..165..166..167..168..169..170..171..172..173..174..175..176..177..178..179..180..181..182..183..184..185..186..187..188..189..190..191..192..193..194..195..196..197..198..199..200..201..202..203..204..205..
>>>>>> > ++ CPU time for realignment=16.6 s  [=0.0808 s/sub-brick]
>>>>>> > ++ Min : roll=-0.008  pitch=-0.103  yaw=-0.096  dS=+0.255
>>>>>> dL=-0.019
>>>>>> >  dP=-0.151
>>>>>> > ++ Mean: roll=+0.031  pitch=-0.011  yaw=-0.045  dS=+0.619
>>>>>> dL=+0.037
>>>>>> >  dP=-0.055
>>>>>> > ++ Max : roll=+0.060  pitch=+0.112  yaw=-0.010  dS=+0.693
>>>>>> dL=+0.075
>>>>>> >  dP=+0.015
>>>>>> > ++ Max displacements (mm) for each sub-brick:
>>>>>> >  0.49 0.65 0.63 0.74 0.69 0.75 0.71 0.77 0.70 0.76 0.67 0.77 0.72
>>>>>> 0.73
>>>>>> > 0.66 0.67 0.67 0.67 0.69 0.70 0.72 0.66 0.71 0.68 0.72 0.67 0.73
>>>>>> 0.68
>>>>>> > 0.73 0.66 0.73 0.66 0.70 0.64 0.72 0.69 0.71 0.71 0.72 0.66 0.66
>>>>>> 0.67
>>>>>> > 0.72 0.70 0.71 0.72 0.71 0.69 0.72 0.72 0.71 0.72 0.72 0.69 0.71
>>>>>> 0.74
>>>>>> > 0.73 0.69 0.72 0.72 0.76 0.76 0.79 0.73 0.75 0.74 0.75 0.75 0.71
>>>>>> 0.74
>>>>>> > 0.67 0.72 0.65 0.72 0.65 0.69 0.69 0.65 0.68 0.64 0.72 0.67 0.67
>>>>>> 0.68
>>>>>> > 0.69 0.65 0.73 0.67 0.71 0.69 0.73 0.72 0.76 0.74 0.72 0.66 0.68
>>>>>> 0.69
>>>>>> > 0.69 0.68 0.68 0.70 0.73 0.70 0.73 0.78 0.74 0.73 0.75 0.74 0.72
>>>>>> 0.74
>>>>>> > 0.63 0.66 0.68 0.74 0.72 0.74 0.79 0.74 0.74 0.76 0.79 0.79 0.74
>>>>>> 0.76
>>>>>> > 0.70 0.75 0.72 0.78 0.74 0.78 0.76 0.80 0.76 0.79 0.77 0.76 0.76
>>>>>> 0.75
>>>>>> > 0.73 0.80 0.78 0.81 0.78 0.84 0.76 0.79 0.77 0.79 0.76 0.83 0.77
>>>>>> 0.79
>>>>>> > 0.77 0.84 0.76 0.80 0.77 0.81 0.72 0.79 0.74 0.80 0.77 0.83 0.81
>>>>>> 0.82
>>>>>> > 0.76 0.81 0.75 0.78 0.74 0.75 0.71 0.75 0.73 0.77 0.77 0.80 0.77
>>>>>> 0.80
>>>>>> > 0.75 0.73 0.77 0.72 0.76 0.72 0.76 0.72 0.72 0.69 0.66 0.68 0.65
>>>>>> 0.68
>>>>>> > 0.64 0.70 0.62 0.70 0.62 0.69 0.67 0.74 0.75 0.74
>>>>>> > ++ Max displacement in automask = 0.84 (mm) at sub-brick 145
>>>>>> > ++ Wrote dataset to disk in 006/tmp.mc-afni2.2758/outvol.nii.gz
>>>>>> > #@# --------------------------------
>>>>>> >
>>>>>> /Users/maryam/mri-space/studies/PDM1/unpackdata/110419_xu_PDM1_02_PDM/bold
>>>>>> > mri_convert 006/tmp.mc-afni2.2758/outvol.nii.gz 006/fmc.nii
>>>>>> --in_like
>>>>>> > 005/f.nii
>>>>>> > mri_convert 006/tmp.mc-afni2.2758/outvol.nii.gz 006/fmc.nii
>>>>>> --in_like
>>>>>> > 005/f.nii
>>>>>> > reading info from 005/f.nii...
>>>>>> > $Id: mri_convert.c,v 1.146.2.5 2009/04/08 18:40:23 nicks Exp $
>>>>>> > reading from 006/tmp.mc-afni2.2758/outvol.nii.gz...
>>>>>> > TR=2000.00, TE=0.00, TI=0.00, flip angle=0.00
>>>>>> > i_ras = (-1, -0.000171665, -3.15037e-05)
>>>>>> > j_ras = (0.000174532, -0.983572, -0.180519)
>>>>>> > k_ras = (-2.07852e-18, -0.180519, 0.983572)
>>>>>> > writing to 006/fmc.nii...
>>>>>> > ... cleaning up ....
>>>>>> > Sun Apr 24 20:43:59 EDT 2011
>>>>>> > mc-afni2 done
>>>>>> > INFO: Making external regressor from mc params
>>>>>> > mcparams2extreg -mcfile 006/fmc.mcdat -northog 6 -extreg
>>>>>> 006/mcextreg
>>>>>> > Logfile is 006/mcparams2extreg.log
>>>>>> > ----------- Matlab file --------------
>>>>>> >   mcfile = '006/fmc.mcdat';
>>>>>> >   extreg = '006/mcextreg';
>>>>>> >   nkeep     = [];
>>>>>> >   northog   = [6];
>>>>>> >   pctorthog = [];
>>>>>> >   monly     = 0;
>>>>>> >
>>>>>> >   mc = textread(mcfile);
>>>>>> >   mc = mc(:,2:7);
>>>>>> >   ntrs = size(mc,1);
>>>>>> >   if(ntrs < 6)
>>>>>> >     fprintf('ERROR: ntrs = %d < 6\n',ntrs);
>>>>>> >     if(~monly)
>>>>>> >       fprintf('Quiting matlab\n');
>>>>>> >       quit;
>>>>>> >       fprintf('should not be here\n');
>>>>>> >     end
>>>>>> >   end
>>>>>> >
>>>>>> >   if(~isempty(nkeep))
>>>>>> >     x = mc(:,1:nkeep);
>>>>>> >   elseif(~isempty(northog))
>>>>>> >     [u s v] = svd(mc);
>>>>>> >     ds = diag(s);
>>>>>> >     pct = 100*cumsum(ds)/sum(ds);
>>>>>> >     x = u(:,1:northog);
>>>>>> >     nkeep = northog;
>>>>>> >     fprintf('INFO: northog = %d, pct = %g\n',northog,pct(nkeep));
>>>>>> >   else
>>>>>> >     [u s v] = svd(mc);
>>>>>> >     ds = diag(s);
>>>>>> >     pct = 100*cumsum(ds)/sum(ds);
>>>>>> >     nkeep = min(find(pct > pctorthog));
>>>>>> >     x = u(:,1:nkeep);
>>>>>> >     fprintf('INFO: pctorthog = %g, nkeep = %d\n',pctorthog,nkeep);
>>>>>> >   end
>>>>>> >
>>>>>> >   x2 = zeros(1,1,nkeep,ntrs);
>>>>>> >   x2(1,1,:,:) = x'; %'
>>>>>> >   %fmri_svbvolume(x2,extreg);
>>>>>> >
>>>>>> >   mri.vol = permute(x2,[1 3 2 4]);
>>>>>> > mri.tr <http://mri.tr> = 0;
>>>>>> >   mri.flip_angle = 0;
>>>>>> >   mri.te = 0;
>>>>>> >   mri.ti = 0;
>>>>>> >   mri.vox2ras0 = eye(4);
>>>>>> >   mri.xsize = 1;
>>>>>> >   mri.ysize = 1;
>>>>>> >   mri.zsize = 1;
>>>>>> >   mri.volres = [1 1 1];
>>>>>> >   mri.volsize = [size(mri.vol,1) size(mri.vol,2) size(mri.vol,3)];
>>>>>> >   fname = sprintf('%s.bhdr',extreg);
>>>>>> >   MRIwrite(mri,fname);
>>>>>> >
>>>>>> > quit;
>>>>>> > -----------------------------------
>>>>>> > ------------------------------------------
>>>>>> > ------- matlab output --------------------
>>>>>> > Warning: Unable to open display 'iconic'.  You will not be able to
>>>>>> > display graphics on the screen.
>>>>>> >
>>>>>> > < M A T L A B (R) >
>>>>>> >                   Copyright 1984-2009 The MathWorks, Inc.
>>>>>> >                  Version 7.9.0.529 (R2009b) 64-bit (maci64)
>>>>>> >                               August 12, 2009
>>>>>> >   To get started, type one of these: helpwin, helpdesk, or demo.
>>>>>> >   For product information, visit www.mathworks.com
>>>>>> > <http://www.mathworks.com>.
>>>>>> > >> >> >> >> >> >> >> >> ??? Error using ==> textread at 167
>>>>>> > File not found.
>>>>>> > >> ??? Undefined variable mc.
>>>>>> > >> ??? Undefined function or variable 'mc'.
>>>>>> > >> ??? Undefined function or variable 'ntrs'.
>>>>>> > >> >> ??? Undefined function or variable 'mc'.
>>>>>> > >> >> ??? Undefined function or variable 'ntrs'.
>>>>>> > >> ??? Undefined function or variable 'x'.
>>>>>> > >> >> >> ??? Undefined function or variable 'x2'.
>>>>>> > >> >> >> >> >> >> >> >> >> >> ??? Reference to non-existent field
>>>>>> 'vol'.
>>>>>> > >> >> ??? Reference to non-existent field 'vol'.
>>>>>> >
>>>>>> > Error in ==> MRIwrite at 70
>>>>>> >   bmri.voldim = [size(mri.vol,1) size(mri.vol,2) size(mri.vol,3)];
>>>>>> > >> >> ------------------------------------------
>>>>>> > ERROR: output not created
>>>>>> > ERROR: mc-sess failed
>>>>>> >
>>>>>> >
>>>>>> >
>>>>>> > _______________________________________________
>>>>>> > Freesurfer mailing list
>>>>>> > Freesurfer@nmr.mgh.harvard.edu
>>>>>> -------------- next part --------------
>>>>>> An HTML attachment was scrubbed...
>>>>>> URL:
>>>>>> http://mail.nmr.mgh.harvard.edu/pipermail/freesurfer/attachments/20110425/d7a55eb3/attachment.html
>>>>>>
>>>>>> ------------------------------
>>>>>>
>>>>>> _______________________________________________
>>>>>> Freesurfer mailing list
>>>>>> Freesurfer@nmr.mgh.harvard.edu
>>>>>> End of Freesurfer Digest, Vol 86, Issue 77
>>>>>> ******************************************
>>>>>>
>>>>>>
>>>>>> The information in this e-mail is intended only for the person to
>>>>>> whom
>>>>>> it is
>>>>>> addressed. If you believe this e-mail was sent to you in error and
>>>>>> the
>>>>>> e-mail
>>>>>> contains patient information, please contact the Partners Compliance
>>>>>> HelpLine at
>>>>>> http://www.partners.org/complianceline . If the e-mail was sent to
>>>>>> you
>>>>>> in error
>>>>>> but does not contain patient information, please contact the sender
>>>>>> and
>>>>>> properly
>>>>>> dispose of the e-mail.
>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>