APL matrix to Excel (was Re: )

Bob -

there's probably a way to write directly to a

.xls file but I'm not sufficiently familiar with

your version of APL to know what it is. However,

the following function should allow you to accomplish

what you want to do by writing your matrix to a

.CSV file which Excel can read.

Here's the function in ASCIIized APL (get Jim Weigang's

APL2ASCI workspace off the web to convert it back to APL

characters): I hope you find it useful.

{del} mat mat2csv flnm;#IO;shape;xx;vec

[1] #IO{<-}1 & shape{<-}{rho}vec{<-}{format}{each}mat

[2] xx{<-} {neg} =({enclose} ){rho}{each}vec{<-},vec

[3] vec{<-}(xx\xx/ - ),{each}xx{drop}{each}vec

[4] mat{<-}(shape{rho}vec),{each} ,

[5]

mat[;{neg}1{take}{rho}mat]{<-}{neg}1{drop}{each}mat[;{neg}1{take}{rho}mat]

[6] flnm #NCREATE {neg}1

[7] (,(({format}mat),#AV[14]),#AV[11])#NAPPEND {neg}1

[8] #NUNTIE {neg}1

{del}

This function puts the numeric matrix "mat" into the file

named by "flnm" as a comma-separated vector, i.e. .CSV

file. Excel can read this as a spreadsheet.

The first line, after setting the index origin to 1,

converts each number in the matrix to character; it also

saves the shape of the matrix and converts it to a vector

for the following few steps.

The second line finds all the high-minuses (negative

signs) so that the third line can replace them with the

minus sign Excel will find acceptable.

Line 4 converts this vector, now with the high-minuses

changed to regular minuses, back to a matrix and puts a

comma after each element. Line 5 gets rid of the last

comma on each line since it is a separator required only

between elements.

Line 6 creates the file requested and line 7 writes the

matrix to this file as a vector after appending CR-LF to

the end of each line. The last line unties the file.

To use this function to write your matrix "MYMAT" to the

file "C:\SIMS\RUN1.CSV", invoke it thusly:

MYMAT mat2csv 'C:\SIMS\RUN1.CSV'

<HR>

<html><div style='background-color:'><DIV>

<DIV>Hello,</DIV>

<DIV>?</DIV>

<DIV>I am relatively new to APL and am working with APL 2000 in

WIndows 98 environment.</DIV>

<DIV>?</DIV>

<DIV>I have a 2 dimensional matrix in my workspace and want to

export it to an excel spreadsheet.?? I'd like to save

the matrix in my C:\SIMS\ directory of my harddrive with the

file name run1.xls.? Does anybody know the source code to

do this?? I've been doing it the cut and paste kind of way

but I'm thinking there has to be a more efficient way to do

this.</DIV>

<DIV>?</DIV>

<DIV>Any help or direction you can offer would be great.</DIV>

<DIV>?</DIV>

<DIV>Thanks in advance.</DIV>

<DIV>?</DIV>

<DIV>-Bob Gallop</DIV>

<DIV>?</DIV>

<DIV>?</DIV></DIV></div><br clear=all><hr>Get your FREE

download of MSN Explorer at <a

href=' http://www.*-*-*.com/ '> http://www.*-*-*.com/ </a><br></html>

__________________________________________________

Do You Yahoo!?

Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.

http://www.*-*-*.com/