Could you just explain what these two lines are actually doing:
guidance 1!:2 (2) mydata =. 0 : 0 I see that guidance is defined as just a print statement prompt, but what is the 1!:2(2) business about? On 4/15/07, Fraser Jackson <[EMAIL PROTECTED]> wrote:
Amelia, I detect a sense of 'panic' about input. Don't worry, professors too sometimes have things they really want to work, and have problems working out exactly what to do. The script below goes much further towards solving your problem than it perhaps should, but you have clearly worked at this, and the discussion on the forum has raised a number of valuable issues. I hope the script clarifies for you why many of us find the task you have been asked to do a step backwards rather than forwards. Of course a J session is just a script entered line by line. I have attached a script in a quite different style which I think your hearers might find easier to understand than a script in the graphics for J primitives. You need to modify it for your problem but it does demonstrate and easy way of incorporating keyboard input. Select the text and copy it to an .ijs window and it should run. Note how it includes functions, and documentation. Modify it - perhaps giving a more general input instruction, and extending the functions output. Try main ' ' and follow instructions. Fraser Script follows ============================================= load 'primitives' guidance =: 0 : 0 Enter a sequence of number pairs Conclude with a left parenthesis in the first position in a row ) main =: 3 : 0 guidance 1!:2 (2) mydata =. 0 : 0 NB. convert mydata to a matrix moddata =. do open box cut _2 mydata NB. moddata is now a numeric array with two columns NB. and you can do what you want with it NB. If you write the commands correctly NB. they will produce an array of the output wanted NB. with a row for each column statfns rank 1 transpose moddata ) Note 'An example follows' You might want to emphasize that in J a natural way to do all this is to have a function main which defines or loads the functions you want, then to enter the data and finally to execute it and return the results of interest. That way the script is a complete documentation of the calculations undertaken. It includes the functions used and the the data or at least where it was obtained from. The output is of course on your session manager window and can easily be saved, or written to a file if wanted. As a statistician who might need to defend the results having a complete record is extremely valuable. How can one recapture the keystrokes entered by a user unless the output in fact includes them? ) maxval =: max insert minval =: min insert range =: maxval - minval statfns =: maxval,minval,range Note 'Defining your output' Simple and subtle changes in the function to generate the statistical values required can modify how the function organises the information required. If your input to the function main consists of lists of numbers of the same length it will return an array. To obtain the statistics for a list of numbers statfns =: maxval,minval,range will provide the definition required. To apply it to each column and have the output of three columns then use statfns rank 1 transpose data_matrix Alternatively you could define a function statfns1 =: maxval,minval laminate range which would place the output with the maxvalues in the first row, the minvalues in the second and the range in the final row with columns corresponding to the original data. ) ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
