Renaming Arrays in ImageJ


#1

Is it possible to rename arrays in ImageJ. I have already define certain arrays in the code, and I have one large chunk of data currently with a bunch of numbers. I wanted to somehow split the array to get certain data sets and then put them on to an excel sheet in different columns, without creating new arrays or creating new array names, so it should be automated. I thought the best way to do it was to rename an array name and create a new column with Arrray.show. Or if it is possible to set the Array.show to a set number of rows so that it create a new column please let know.


#2

Dear @zing,

as you have noticed Array.show(a1, a2, a3) will generate a ResultsTable with the columns, a1, a2, and a3. You can circumvent this by doing some manual work:

run("Clear Results");

testArray = newArray(1,2,3,4,5,6,7,8,9,10);
for (i=0; i<lengthOf(testArray)/2; i++) {
   setResult("ArrayName1", i, testArray[i]);
   setResult("ArrayName2", i, testArray[4+i]);
}
setOption("ShowRowNumbers", false);
updateResults;

You can also combine that approach with Array.slice to create temporary arrays from the “one large chunk of data”.

Best,
Stefan


#3

Is it possible then to try and remove arrayname1 for a variable so that is constantly compiles it so that it is in a different row?

Thank you for you help,

Zing


#4
run("Clear Results");
nameInVariable = "ArrayName1";

testArray = newArray(1,2,3,4,5,6,7,8,9,10);
for (i=0; i<lengthOf(testArray)/2; i++) {
   setResult(nameInVariable, i, testArray[i]);
   setResult("ArrayName2", i, testArray[4+i]);
}
setOption("ShowRowNumbers", false);
updateResults;

#5

So currently what I have Is something like this:

    for (z=0; z<5; z++) {
        /*Compiling data here and setting to create another excel sheet for
        because I have the results on another results table*/
        run("Clear Results");
        nameInVariable = "ArrayName1";
   
        testArray = newArray(1,2,3,4,5,6,7,8,9,10);
        for (i=0; i<lengthOf(testArray)/2; i++) {
           setResult(nameInVariable, i, testArray[i]);
           setResult("ArrayName2", i, testArray[4+i]);
        }
        setOption("ShowRowNumbers", false);
        otherpath = saveDir +"Directory.xls"; 
        saveAs("text" , otherpath); 
    }

I clear the results before running the setResults to remove any data I have and put it into another excel spreadsheet. Then I run the code again. So when I do this the setResults does not compile on to another array instead it replaces what I currently have with new results, but I do not want that instead I wanted it to be in a column right beside it. I have tried this method for putting setResults but the run(“Clear Results”) keeps removing the data I already have.

Note saveDir is where I select a directory in the beginning of my code.

Thank you for you help,

Zing


#6

What do you want to call that column? You can make the column name depend on z for example: setResult("Array"+z, i, testArray[i]). This will create a column called Array0, then a column called Array1, etc.

Why don’t you remove the run("Clear Results") then? Try it, you can’t break anything. If you are unsure about the macro language itself, I’d suggest taking a look at the documentation as well as the built-in functions.