APL matrix to Excel (was Re: ) 
Author Message
 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/



Sat, 15 May 2004 22:57:20 GMT  
 APL matrix to Excel (was Re: )
Bob,

In APL2000 you can fire up MS Excel as a COM object, load a workbook, write
directly to any range on any worksheet, and save the revised workbook .. all
under APL control.  

See the demo workspace XLINAPL at the APL 2000 web site http://apl2000.com.
The functions of immediate interest to you would probably be:

XL_Init to fire up a copy of Excel
XL_Data to write data to the active worksheet.
XL_Save to save the .xls file
and XL_Quit to close Excel

Regards,

Larry Mysz
Customized Applications,Inc
http://customized-applications.com

 --------------------

Quote:
>>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? <<


Wed, 19 May 2004 07:56:25 GMT  
 APL matrix to Excel (was Re: )
APL 101 problem with this function: it does two separate things,
which implies it should be two functions,

      {del}CSV{<-}CSVofMAT MAT
...[1..5]

      {del}filename SetFile data
...[6..8]

used as follows:

      filename SetFile CSVofMAT mat

Quote:

> 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}



Mon, 31 May 2004 22:34:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. I am looking for a vi that will do 2D or matrix interpolation

2. Question: Tri-diagonal matrices in APL

3. APL matrix inverse

4. Matrix chain product: FORTRAN vs. APL title bout

5. APL+Win reading from Excel

6. APL and Excel ActiveX control

7. APL and Excel ActiveX control

8. APL2000 APL/Excel Paper/Tutorial

9. Fw: APL to and from Excel

10. APL to and from Excel

11. Access and APL -- How about Excel

12. speaking of Excel (and APL)

 

 
Powered by phpBB® Forum Software