imageName=getTitle();#这将返回一个包含图像所在位置的整个路径的字符串。
image1 = split(imageName,"/");#拆分"/“所在的图像。根据路径,这在长度上是不同的。
image = image11;#我想要最后一个,但它并不总是第n个索引。
发布于 2021-12-14 20:37:25
split()返回一个数组。在您的示例中,您将数组分配给image1,这样就可以使用image1.length找到数组的长度。ImageJ宏语言中的数组是基于0的,因此需要减去1才能找到最后一个元素。
imageName=getTitle(); #This returns a string with the entire path of where the image is.
image1 = split(imageName,"/"); #splits the image where "/" is. Based on path, this varies in length
image = image1[image1.length - 1]; #last element.请注意,使用/进行拆分将在mac上有效,但在Windows上不起作用。
我的回答是针对你的索引问题。如果您只是想要没有路径的文件名,请查看File.name和File.nameWithoutExtension,以获得所需的更简单的方法。
https://stackoverflow.com/questions/70354753
复制相似问题