On Sep 11, 2006, at 5:08 PM, David Mitchell wrote:

Benedict G Archer wrote:
Been playing with J for a year+ and can do some useful things, but thought a good way to advance would be to use J for things I do all the time. Gave 40 students a chem test with 80 questions and have an array with the first column containing student names and the remaining columns for scores on each question. The task is to evaluate the test questions--e.g., which did everyone get right, any that everyone missed, etc. I'm trying to write the array to a file in a way that I can get it back easily and work with it. In APL2 I could save a workspace; in Matlab or Octave I could save a file, but haven't been able to figure out how to write the J noun to a file and get it back. 'm' fread, after fwrite, seems to count the box characters as part of the array, and freads isn't useful, at least in my attempts, either. Do I need to use a mapped file? I expect to be red-faced when someone tells me where the answer is in the help docs or the lab that shows how, but it's time for me to admit I need help. Suggestions on a best J approach to this simple task also welcome.
Thanks in advance,
Ben Archer

Ben,

Perhaps this example is what you want:

   load'jfiles'
   jcreate 'foofile'
1
   res=. 3 1$'Joe';'Sue';'Rasputin'
   res=.res,.<"0]3 4$12?12
   res
+--------+-+-+--+--+
|Joe     |0|6|11|10|
+--------+-+-+--+--+
|Sue     |3|1|4 |2 |
+--------+-+-+--+--+
|Rasputin|9|5|7 |8 |
+--------+-+-+--+--+
   (<res) jappend 'foofile'
0
   jsize 'foofile'
0 1 2304 0
   q=.>jread 'foofile';0
   q
+--------+-+-+--+--+
|Joe     |0|6|11|10|
+--------+-+-+--+--+
|Sue     |3|1|4 |2 |
+--------+-+-+--+--+
|Rasputin|9|5|7 |8 |
+--------+-+-+--+--+

--
All the best,
David Mitchell
Right, that's exactly what I was trying to do. The critical thing I didn't know was that I had to box (<) res before appending and open (>) when reading. I had tried itemize (,:), but got a _3 return code, and stopped trying to use jfiles. Still seems that itemizing res should work; I'll study the docs and experiment to get more insight into ,: . (Some of the documentation is quite terse.)

The cvs functions work too. I hadn't tried them before. (Thanks, R.E.Boss). I had tried the 3!: conjuctions. Chris Burke's example showed me my mistakes there. With the 3!:1/3!:2 method it's not necessary to box/open the array to write/read the file as it is with the jfiles functions.

Thanks all; I have three ways now.
Ben A


================================
Benedict G. Archer
[EMAIL PROTECTED]



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to