Finding a minimum value in a table txt file

statistics
results-table
Tags: #<Tag:0x00007fd699d5b610> #<Tag:0x00007fd699d5b430>

#1

Hi,
In a macro, I creating a table txt file in which I write several X and Y value of specific point in a image.

I would like then find the minimum value in the Y column in order to use it again in my macro.
I manage to find a minima or maxima in the Result table by the following code:
Y_minimum=getResult(“Area”,1);

for(n=1;n<nResults;n++){
	if(getResult("Y_noir",n)<Y_minimum){
		Y_minimum=getResult("Y_noir",n);
	}
}

The problem is to transform the txt table file in a Results table.
I try this

selectWindow("Coord_point_noir.txt");
IJ.renameResults("Results");

but Fiji told me that “Coord_point_noir.txt” is not a result table.

The whole macro (removing many lines for confidentiality reasons) is the following:

    title1 = "Coord_point_noir.txt"; 
    title2 = "["+title1+"]"; 
    f1=title2; 
    run("New... ", "name="+title2+" type=Table"); 
    print(f1,"\\Headings: \tX_noir\tY_noir");  // 3 columns
    [...]
    	   	if(getResult("Value",0)==0){
    	   		for(t=0;t<nResults && !done3;t++){
    		    	if(getResult("Value",t)==255){
    		    		X_noir=X_AOI_gauche+r;
    		    		Y_noir=Y_AOI_haut+t;
    		    		print(f1, ww +" \t" + X_noir +" \t" + Y_noir); // ww is 1, 2,.... until n, where n is the number of line. This number is not really necessary. I tried with ww in order to see if the txt file was accepted as Result Table.
    		    		done3=true;
    		    	}
    			}
    			run("Clear Results");
    		}
    IJ.deleteRows(0, nResults);
    selectWindow("Coord_point_noir.txt"); // The windows is still opened
    save(chemin+"Coord_point_noir.txt");   
    
    IJ.renameResults("Results"); /// PROBLEM HERE
    
    Y_minimum=getResult("Area",1);
    for(n=1;n<nResults;n++){
    	if(getResult("Y_noir",n)<Y_minimum){
    		Y_minimum=getResult("Y_noir",n);
    	}
    }

If you have better idea to find the minimum value in the Y column of Table txt file, feel free to propose it! :slight_smile:

Thanks in advance


#2

Good day Fabien,

could you please tell the forum what a “table txt file” is?

Regards

Herbie


#3

Hi,

It is probably not the good term. In fact, I would like to say a txt, filled by:
print(f1,"\\Headings: \tX_noir\tY_noir")
which is seen like a Table when you open it in imageJ.

In fact, carandraug on IRC suggest me to save Y value in an array and then use Array.getStatistic, which works very well.

So my problem is resolved!