8
$\begingroup$

I created a grid g1 with Grid[] and then a separate grid g2. g1 and g2 have same number of columns. How to put the rows of g2 at the end of g1 purely using front-end? I tried to highlight g2, Ctrl+C, and move my curser to various positions in g1 and Ctrl+V. But it always resulted in something not desirable such as the entire g2 being copied into a cell of g1. Any suggestions?

$\endgroup$
4
  • $\begingroup$ So You want to create something like Grid@{gi1, gi2,...,hi1,hi2..} without evaluating anything? (gi1 is first row of g grid). Or do You want it to only look like grid with more rows? $\endgroup$
    – Kuba
    Jun 6, 2013 at 5:52
  • $\begingroup$ something like that: g1 = Grid[{{a, b}, {c, d}}, Frame -> All], g2 = Grid[{{w, x}, {y, z}}, Frame -> All], and then g3=Grid[g1[[1]]~Join~g2[[1]], Frame -> All]? $\endgroup$ Jun 6, 2013 at 5:53
  • $\begingroup$ @PinguinDirk You're right. $\endgroup$
    – qazwsx
    Jun 6, 2013 at 6:29
  • $\begingroup$ Could you explain why you would want to do something like that using the FrontEnd? I honestly can't find a good use for it. If you'd have to recalculate either of those grids for whatever reason you'd have to manipulate them again in the FrontEnd. Very cumbersome. $\endgroup$ Jun 6, 2013 at 22:26

3 Answers 3

6
$\begingroup$

Say you have two Grid:

enter image description here

First place the cursor at the end of the last row:

enter image description here

Then use menu command Add Row (please note the short-cut) to add as many rows as g2 has:

enter image description here

enter image description here

Then copy g2 by dragging from the items (not by select the whole grid or cell!):

enter image description here

Then select all empty rows you just created in g1 and paste:

enter image description here

enter image description here

$\endgroup$
5
  • $\begingroup$ Can you think of any way to do this without creating as many rows as needed manually? I cannot think of a way myself, though I'm hoping one exists. +1 nevertheless. $\endgroup$
    – Mr.Wizard
    Jun 6, 2013 at 6:09
  • $\begingroup$ @Mr.Wizard Thanks. I can't think of one for now, so I would not suggest doing this for large grid.. I'll try it after lunch. Maybe something related to ArrayFlatten.. $\endgroup$
    – Silvia
    Jun 6, 2013 at 6:16
  • $\begingroup$ @Silvia's solution is acceptable for my problem at hand. But in general, having to click once for each new row needed seems rather bad. $\endgroup$
    – qazwsx
    Jun 6, 2013 at 6:35
  • $\begingroup$ @red3y3 To make it feeling (slightly) better, you can press the short-cut instead of click the menu. But still, this is very annoy. $\endgroup$
    – Silvia
    Jun 6, 2013 at 6:51
  • 1
    $\begingroup$ @Mr.Wizard I give up.. I think it's too complicated FE programming for a not-so-useful function.. $\endgroup$
    – Silvia
    Jun 6, 2013 at 9:14
4
$\begingroup$

Here is another approach: define a function which can combine two grids preserving the union of their options.

rows = Partition[Range[5 3], 3];
g1 = Grid[rows[[;; 3]], Frame -> All]

g1.png

g2 = Grid[rows[[4 ;;]], Frame -> All]

g2.png

JoinGrids[Grid[data1 : {__}, opts1 : ___], 
          Grid[data2 : {__}, opts2 : ___]] := 
  Grid[Join[data1, data2], Sequence @@ Union[{opts1, opts2}]]

JoinGrids[g1, g2]

join12.png

JoinGrids[g2, g1]

join21.png

g3 = Grid[rows[[4 ;;, ;; 2]], ItemStyle -> Red]

g3.png

JoinGrids[g2, g3]

join23.png

$\endgroup$
0
$\begingroup$

Note that the first argument (not including options to Grid) is a 'matrix' (that is a List of Lists in Mathematica).

Given the following example Grids:

Grid[
    {{a11, a12, a13},
    {a21, a22, a23},
    {a31, a32, a33}}
] 

Grid[
    {{b11, b12, b13},
    {b21, b22, b23},
    {b31, b32, b33}}
]

(Note that I have spread the syntax for each Grid over several lines using a keyboard return, but each Grid expression should be contained within a single notebook cell; see the brackets off to the right in the Front End.)

You should place a comma after the last 'row' of your first 'matrix', like so:

Grid[
    {{a11, a12, a13},
    {a21, a22, a23},
    {a31, a32, a33} , }
]

Then you copy the rows from your second Grid, being careful not to copy the outer curly braces, like so:

enter image description here

You then paste that copied set of lists ('rows' if you prefer) after the comma in your first Grid:

Grid[
    {{a11, a12, a13},
    {a21, a22, a23},
    {a31, a32, a33},
    {b11, b12, b13},
    {b21, b22, b23},
    {b31, b32, b33}}
]

With a shift-enter to evaluate the cell, you should have a nice Grid,

enter image description here

which you can then decorate with options to Grid.

$\endgroup$
1
  • $\begingroup$ That's not what i meant. I want to operate on the resultant grids, not the defining code. $\endgroup$
    – qazwsx
    Jun 6, 2013 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.