Help with import results with criteria

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with import results with criteria

Moniraj Ghosh
Hi,
I am trying to import results table based on a certain criteria and I keep on getting a "out of range" error. Can someone help to figure what is wrong in the macro? The modification is in the last 8 lines. It is based on the import results table macro.
Thanks
_____________________________________

// Import Results Table
//
// This macro populates a fresh "Results" table
// from a saved ImageJ results table, or from
// any tab or comma-separated data file.

// This macro is built into ImageJ 1.38r and
// later as the File>Import>Results command.

 macro "Import Results Table" {
     requires("1.35r");
     lineseparator = "\n";
     cellseparator = ",\t";

     // copies the whole RT to an array of lines
     lines=split(File.openAsString(""), lineseparator);

     // recreates the columns headers
     labels=split(lines[0], cellseparator);
     if (labels[0]==" ")
        k=1; // it is an ImageJ Results table, skip first column
     else
        k=0; // it is not a Results table, load all columns
     for (j=k; j<labels.length; j++)
      setResult(labels[j],0,0);

     // dispatches the data into the new RT
     run("Clear Results");
     for (i=1; i<lines.length; i++)
    {
        items=split(lines[i], cellseparator);

      if(items[8] <=1.3)
         {
                for (j=k; j<items.length; j++)
           setResult(labels[j],i-1,items[j]);
         }
     }
     updateResults();
 }
Reply | Threaded
Open this post in threaded view
|

Re: Help with import results with criteria

Gabriel Landini
On Saturday 09 Apr 2011, Moniraj Ghosh <[hidden email]> wrote:
> I am trying to import results table based on a certain criteria and I keep
> on getting a "out of range" error. Can someone help to figure what is
> wrong in the macro?

Without running it, this caught my eye:

>       if(items[8] <=1.3)

You need to parse the string into a double.
At the moment you are comparing a string to a number.

Regards

G.
Reply | Threaded
Open this post in threaded view
|

Re: Help with import results with criteria

Moniraj Ghosh
In reply to this post by Moniraj Ghosh
Hi,
I got a solution. i had to add an else statement as follows, which adds a "NaN" for every skipped row ( that does not match the criterion). However this is not exactly what I want. I do not want to import the row that does not match the criterion at all. Is there a way to do it?

Thanks so much for your reply.

....
 items=split(lines[i], cellseparator);

      if(items[8] <=d2s(1.3,1))
         {
                for (j=k; j<items.length; j++)
           setResult(labels[j],i-1,items[j]);
         }else
         {  for (j=k; j<items.length; j++)
           setResult(labels[j],i-1,NaN);

        }
   }
    updateResults();

}
Reply | Threaded
Open this post in threaded view
|

Re: Help with import results with criteria

Gabriel Landini
In reply to this post by Moniraj Ghosh
On Saturday 09 Apr 2011, Moniraj Ghosh wrote:
> this is not exactly what I want. I do not want to import the row that does
> not match the criterion at all. Is there a way to do it?

Import everything and then delete the unecessary rows.

From the Functions page in the IJ site:
http://imagej.nih.gov/ij/developer/macro/functions.html

IJ.deleteRows(index1, index2) - Deletes rows index1 through index2 in the
results table.

Cheers
G.