0

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);

1 Answer 1

2

Because all/ph[1-34].nii matches at most 4 files: all/ph1.nii, all/ph2.nii, all/ph3.nii, and all/ph4.nii.

In shell patterns, a construction of the form [char1-char2] matches the characters which sort between char1 and char2; so [1-34] matchs 1, 2, 3 and 4.

You may want to change the for loop to

for i in $(seq 1 $coil)
do
    ph=all/ph${i}.nii
    ...
done
2
  • Thank you. However, it is still not working. I have files from all/ph1.nii to all/ph34.nii. I am getting the error 'Dimensions of matrices being concatenated are not consistent.' Not sure what that means. Can you please suggest anything else? Commented Nov 22, 2018 at 19:57
  • It is working -- that's an error message from your application prelude. It has nothing to do with the shell, or with Linux. I cannot possibly know what your application does, and what parameters and data it expects; you may want to ask on a specialized forum dedicated to the specific application. Commented Nov 22, 2018 at 21:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.