Howdy-
Can you use the regular, ol' AFNI programs for this: 3dROIstats, 3dmaskave, 3dNetCorr etc.? That is, run these commands on the terminal, like with the system() functionality in Matlab, or just in the terminal directly? That strikes me as easier, but there are several AFNI programs for making/applying masks and averaging time series, etc. I am not sure about Matlab functionality, but if you provide more details about the files you have and what you want to do exactly with them, I can probably help out with AFNI commands.
A lot of this is described in this AFNI Academy YouTube playlist:
[
www.youtube.com]
... with the accompanying slides/script:
afni_open -aw afni11_roi.pdf
and this file:
[
afni.nimh.nih.gov]
--pt