0
votes

After some image processing using ImgaeJ macro, I have a ‘Results’ tab which contains 2 columns A and B. Lets’s say I have 50 rows of data.

Now I want to subtract the value of last row from all other 49 rows above in column B.

After this, I want to write all the values in “.csv” file (column A, B and C with 49 values each).

Below is the part of the code. I think the only problem is fetching the values from arrays that the script can write to the csv file.

Array.getStatistics command only exports the mean, std values for a given column. I'm interested in fetching all 49 values.

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";

A = newArray(nResults() - 1);
B = newArray(nResults() - 1);

D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    A[i] = getResult("A", i);
    B[i] = getResult("B", i);
    C[i] = A[i] - D;
}

Any idea about what is the command to get the values of A[i], B[i] and C[i]?

Looking forward for some help here.

Thank you.

1

1 Answers

0
votes

One solution is to write to the file as you do the calculations. I have modified your example (untested) to show how this works.

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";
f = File.open(resultFilename);

A = newArray(nResults() - 1);
B = newArray(nResults() - 1);
// no C array is made so:
C = newArray(nResults() - 1);
D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    A[i] = getResult("A", i);
    B[i] = getResult("B", i);
    C[i] = A[i] - D;
    // should the line above should be C[i] = B[i] - D;
    print(f, d2s(A[i],6) + "  \t" + d2s(B[i],6) + " \t" + d2s(C[i],6));
}
File.close(f);

Note that you don't need to make the arrays at all and can just write to the file (again this is untested):

directory = getDirectory("Choose a Directory");
resultFilename = directory + Dialog.getString() + ".csv";
f = File.open(resultFilename);

D = getResult("B", nResults() - 1);
    
for (i = 0; i < nResults() - 2; i++) {
    ai = getResult("A", i);
    bi = getResult("B", i);
    ci = ai - D;
    // should the line above should be ci = bi - D;
    print(f, d2s(ai,6) + "  \t" + d2s(bi,6) + " \t" + d2s(ci,6));
}
File.close(f);

I have used " \t" (tab character) as a separator not comma.