 # How do I concatenate matrices in GAUSS?

I have a matrix of observations and I want to add a constant vector as the first row of my matrix. How can I concatenate these two variables in GAUSS?

0

### Numerical data

For matrices and vectors use the tilde `~` operator for horizontal concatenation and the pipe `|` operator for vertical concatenation.

For example if you have two 3x1 vectors A and B, you can concatenate them into a 3x2 matrix like this:

``````A = { 1,
2,
3 };

B = { 4,
5,
6 };
new_mat = A ~ B;``````

will assign `new_mat` to be the following matrix:

```1 4
2 5
3 6```

You could vertically concatenate them into a 6x1 vector like this:

``````A = { 1,
2,
3 };

B = { 4,
5,
6 };
new_mat = A | B;``````

will assign `new_mat` to be the following vector:

```1
2
3
4
5
6```

### String Arrays

String arrays use the tilde `~` and pipe `|` operators, but they are prepended with the dollar sign `\$`. For example:

``````string sa_A = { "alpha",
"beta" };
string sa_B = { "gamma",
"delta" };

// Horizontal string concatenation
sa_C = sa_A \$~ sa_B;

// Vertical string concatenation
sa_D = sa_A \$| sa_B;``````

after the code above:

``````sa_C = "alpha" "gamma"
"beta"  "delta"

sa_D = "alpha"
"beta"
"gamma"
"delta"`````` ### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.