mercredi 17 janvier 2018

ImageJ Executing If Statement Multiple Times in For Loop

I have a nested pair of for loops, which has two different conditions (i.e. Day 1, Day 4, Day 12; and number options 1-10) that have to be iterated through. I added a for loop which is intended to check if the file is in the input folder. It does so properly, but runs the complete function as many times as there are Days.

As in, for a data set like:

Day1_Sample1a Day4_Sample2a Day1_Sample1b Day4_Sample2b Day1_Sample2a Day6_Sample3a Day1_Sample2b Day6_Sample3b

I can get the function to run, but if I include the close } bracket for the function, it will print the above values as many times as the highest index value for the time points array. Is there something I'm missing here? The if statement is there to allow the macro to skip a possible file name if the sample number isn't present in the folder.

function processFile(inputFolder, outputFolder, file) {
for (h = 0; h < timePoints.length; h++) {
            for (j = 1; j<NumberOptions.length+1; j++) 
            {
  a = inputFolder+timePoints[h]+"_Sample"+j+"a"+filetype
  b = inputFolder+timePoints[h]+"_Sample"+j+"b"+filetype
if (File.exists(inputFolder+a)==true&&File.exists(inputFolder+b)==true) {
  print(a);
  print(b);
   }
  }
 }
}

Aucun commentaire:

Enregistrer un commentaire