【问题标题】:Printing Array Items by Index Number in ImageJ (Fiji)在 ImageJ(斐济)中按索引号打印数组项
【发布时间】:2018-01-11 11:48:13
【问题描述】:

我试图弄清楚如何通过索引号访问数组中的项目。我编写了一个脚本,它将生成一个带有一些变量的数组。 imageJ 邮件列表存档中有一个旧脚本(如下所示),它能够为数组中的已知值打印给定的索引值,但是有没有办法在数组本身中找到该值? IE。如果我让用户输入应该在数组中的值的数量,我可以让宏从中调用数组中的值吗?

我的数组生成器:

Dialog.create("Time Point Input");
Dialog.addNumber("How many time points?", 0)
Dialog.addString("What are your time points (comma separated, no spaces)?:",0);
Dialog.show();
time = Dialog.getNumber();
points = Dialog.getString();
Fpoints = newArray(points);

读数可能是这样的:

time = 4
points = 5,10,12,27

Fpoints[0] = 5
Fpoints [1] = 10
Fpoints [2] = 12
Fpoints [3] = 27

从数组数值调用索引示例代码:

arr = newArray(1,5,3,12); 
i = index(arr, 5); 
print("index = "+i); 

  function index(a, value) { 
      for (i=0; i<a.length; i++) 
      if (a[i]==value) return i; 
  return -1; 
 } 

谢谢!

【问题讨论】:

    标签: arrays macros imagej imagej-macro fiji


    【解决方案1】:

    我不能 100% 确定你的问题是否正确。

    但是有没有办法在数组本身中找到值?

    问题是你不能用points 创建一个数组,因为它是一个字符串。 试试链接:

    Fpoints = split(points, ',');
    

    然后您可以使用循环遍历 Fpoints,或者使用您的索引函数来获取给定值的索引。

    for (i = 0; i < Fpoints.length; i++) {
        print(Fpoints[i]);
    }
    

    【讨论】:

    • 非常感谢!循环是我一直在寻找的。我没有意识到我必须拆分字符串才能通过索引找到其中的项目。遍历列表正是我需要让脚本的其余部分工作。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 2023-03-21
    • 1970-01-01
    • 2021-08-06
    相关资源
    最近更新 更多