Krista:
There is an easier way to do what you want. You need to multiply the mask dataset bob suggested ROI_STAT by a clust_order mask dataset from 3dmerge.
If 34_mask+tlrc is your file with 34 ROIs, then type:
3dmerge -1clust_order rmm vol -prefix 34_mask_clustorder 34_mask+tlrc
input whatever clustering options you want, but since you already have your ROIs you may want to be lenient here just to make sure you dont eliminate any small ROIs.
The -1clust_order option labels each 'cluster' in your mask file with a unique number based on the ROI volume size. Largest ROI = 1, smallest = 34.
Next, multiply this dataset by ROI_STAT+tlrc
3dcalc -expr 'a*b' -a ROI_STAT+tlrc -b 34_mask_clustorder+tlrc -prefix 34_mask_clustorder_threshold
The output file now contains threhsolded data for each ROI, with different numbers assigned to each ROI. For example, all 1's are the voxels in your largest cluster that passed threshold, all 2's are the voxels in your second largest cluster that passed threshold, etc.
Use the 3dmaskavg option -mrange to select only the ROI you want to output.
-mrange .9 1.9 will grab all 1's in your mask. I guess you will have to create 34 command lines, stepping up the mrange as you go to just grab 1's, then 2's, then 3's etc.
Alternativley, if you are just after the average timecourse for all thresholded values for each ROI in your ROI mask, the program 3dROIstats may be an easier route. It automatically detects how many uniquely numbered ROIs there are in your mask and averages each of them separately. You can even tell it not to average in any zeros, if some subjects dont have coverage over an entire ROI. Also, this program can handle input files with multiple subbricks, so you can get the average evoked response for timepoint 1, then timepoint 2, etc.
Hope this helps,
Christine Smith