0

在使用 ImgaeJ 宏进行一些图像处理后,我有一个“结果”选项卡,其中包含 2 列 A 和 B。假设我有 50 行数据。

现在我想从 B 列上面的所有其他 49 行中减去最后一行的值。

在此之后,我想将所有值写入“.csv”文件(A、B 和 C 列,每列 49 个值)。

下面是部分代码。我认为唯一的问题是从脚本可以写入 csv 文件的数组中获取值。

Array.getStatistics 命令仅导出给定列的平均值、标准值。我有兴趣获取所有 49 个值。

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

知道获取 A[i]、B[i] 和 C[i] 值的命令是什么吗?

期待在这里得到一些帮助。

谢谢你。

4

1 回答 1

0

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.

于 2021-03-07T20:48:53.900 回答