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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm