1

I currently have a 3 by 3 matrix "m":

1 2 3
4 5 6
7 8 9

I would like to add a row to matrix 'm' to have a resultant matrix of:

1 2 3
4 5 6
7 8 9
10 11 12
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
  • 2
    How did you create the matrix in the first place? What have you tried that did not work? SO works much better if you provide detail and examples of what you have tried and what happened when you did so. Not really a place to ask bare 'how to' questions. – Anne Gunn Mar 02 '16 at 22:32

2 Answers2

4

A matrix in q is just a list of lists where inner lists represent rows.

m: ((1 2 3);(4 5 6);(7 8 9))

In order to add one more row all you have to do is add one more inner list to it:

m: m,enlist 10 11 12

enlist is important here, without it you'll end up with this:

q)((1 2 3);(4 5 6);(7 8 9)),10 11 12
1 2 3
4 5 6
7 8 9
10
11
12
Igor Korkhov
  • 8,283
  • 1
  • 26
  • 31
0

I agree; using 0N!x to view the structure is very useful.

To achieve what you want then you can simply do;

q)show m:3 cut 1+til 9 /create matrix
1 2 3
4 5 6
7 8 9
q)show m,:10 11 12 /join new 'row'
1  2  3 
4  5  6 
7  8  9 
10 11 12
q)