# Extract Columns from Matrix [closed]

I want to extract columns 3 and 4 from the matrix below:

mat1=Table[{n, ksi,
r = c /. FindRoot[
SpheroidalS1[1, n, c, ksi], {c, BesselJZero[n + 1/2, 1]}
],
r*ksi},
{n, 4}, {ksi, {100, 250, 600, 950}}
] // Flatten[#, 1] & // Prepend[(Style[#, 14, Bold] & /@ {"n", "ksi", "c", "c*ksi"})] // Grid[#, Frame -> All] &

mat2=mat1[[3;;4,1;;16]]


But I get the following message:

Part::take: Cannot take positions 3 through 4 in Grid[Prepend[{n,ksi,c,c*ksi}][{{1,100,4.66544,466.544},<<14>>,{4,950,8.18302 -3.30575*10^-6 I,7773.87 -0.00314046 I}}],Frame->All]. >>

What gives?

• Replace // Grid with ;mat1//Grid in your code. Then run mat1[[All, 3 ;; 4]] – dan7geo Oct 26 '16 at 18:19
• More generally, never include the wrapper (e.g., Grid, Table, Row, Column) as part of the definition of the data. You can use parentheses to isolate the wrapper from the definition, e.g., (mat1 = ...)//Grid[#, Frame -> All] & – Bob Hanlon Oct 26 '16 at 18:24

the problem is mat1 is not a matrix or list, but a Grid. Your Table (with header row) appears as the first part of the Grid object, so you can do this:

 mat1[[1,All, 3 ;; 4]]


Note you also transposed the row/column order.

If you want to display that as a Grid : mat1[[1, All, 3 ;; 4]] // Grid[#, Frame -> All] &

Really you'd be better off to save the Table and only apply Grid when you want to display in formatted form. One way to do that is to add parenthesis to your code:

(  mat1 = Table[]... ) // Grid

• I don't get the desired results through: mat1[[1,All, 3 ;; 4]]. My results are {{1, 600, 4.4951, 2697.06}, {1, 950, 4.49248, 4267.86}}. Any suggestions? – George Giannoulis Oct 26 '16 at 19:02

I had to delete //Grid[#, Frame -> All] & and then as you suggested mat2 = mat1[[1, All, 3 ;; 4]]. Thank you all for your recommendations!

• With the headings mat1[[All, 3;;4]] or mat1[[All, {3,4}]]. Without the headings mat1[[2;;, 3;;4]] or mat1[[2;;, {3,4}]] – Bob Hanlon Oct 26 '16 at 19:20