In the following script, the for loop only outputs till unph4. I tried to write the value of $coils directly but doesn't work as well. I tried other iteration values to see the maximum I am getting is 9 (does the iteration number have to be a single digit?)
coil=34;
bash_command = sprintf(['for ph in all/ph[1-$coil].nii\n' ...
'do\n' ...
' base=`basename $ph`;\n' ...
' dir=`dirname $ph`;\n' ...
' mag=$dir/"mag"${base:2};\n' ...
' unph="unph"${base:2};\n' ...
' prelude -a $mag -p $ph -u $unph -n 12&\n' ...
'done\n' ...
'wait\n' ...
'gunzip -f unph*.gz\n']);
unix(bash_command);