Login  Register

Importing array from text file

Posted by Martin Jaekel on Nov 20, 2007; 5:40pm
URL: http://imagej.273.s1.nabble.com/Importing-array-from-text-file-tp3697966.html

Hi,

I wrote the following macro to label cell nuclei in my embryo pictures. I
import x and y coordinate values into arrays xcoor and ycoor from text
files. These text files are created by simply copy pasting Excel columns
into a TextEdit window on a mac and saving them as .txt.


macro "map nuclei"
{

// ------ Read info of open image ------------------------------------

IID = getImageID();
run("RGB Color");
Yfact = getHeight();
Xfact = getWidth();

// ------ Read .txt file of x coordinates into array -----------------

string = File.openAsString("");
xlines = split(string, "\n");
n_xlines = lengthOf(xlines);

xcoor=newArray(n_xlines);
for (n=0; n<n_xlines; n++)
    {
    xcoor[n] = xlines[n];
    }

// ------ Read .txt file of y coordinates into array -----------------

string = File.openAsString("");
ylines = split(string, "\n");

n_ylines = lengthOf(ylines);
ycoor=newArray(n_ylines);
for (m=0; m<n_ylines; m++)
    {
    ycoor[m]= ylines[m];
    }

// ------ Map nuclear positions on embryo picture --------------------

setColor(255, 50, 0);
setLineWidth(1);

for (i=0; i<n_xlines; i++)
    {
    X=xcoor[i]/100*Xfact-2;
    Y=ycoor[i]/100*Yfact-2;
    selectImage(IID);
    drawOval(X, Y, 4, 4);
    }
}


The values from the text file (I copy-paste columns from Excel into Text
Edti and Save) get stored in the appropriate arrays (xcoor, and ycoor). But
on line 48

'X=xcoor[i]/100*Xfact-2;'

a weird error occurs

';' expected in line 48
X = xcoor[i] </> 100 * Xfact -2;

Why can it not divide the xcoor value?
If I add commas to the .txt file manually and then copy-past them into the
macro (instead of reading them in automatically) the macro does not have
this problem. Any ideas?


Thanks martin