在使用ImgaeJ宏进行了一些图像处理之后,我有了一个“结果”选项卡,其中包含两列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;
}
你知道获取Ai,Bi和Ci的值的命令是什么吗
希望在这里能得到一些帮助。
谢谢。
发布于 2021-03-08 04:48:54
一种解决方案是在进行计算时写入文件。我已经修改了你的例子(未测试)来展示它是如何工作的。
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);
请注意,您根本不需要创建数组,只需写入文件即可(同样,这是未经测试的):
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);
我使用“\t”(制表符)作为分隔符,而不是逗号。
https://stackoverflow.com/questions/66518065
复制相似问题