# How to merge arrays in julia

**URL:** <https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 9, 2020, 12:42pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520 "2020-12-09T12:42:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [December 9, 2020, 12:42pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520/1 "2020-12-09T12:42:52Z")

</div>

Hello,  
I have two arrays like this:

```julia
ulia> soln1
retcode: Success
Interpolation: Automatic order switching interpolation
t: 5-element Array{Float64,1}:
 0.0
 0.23056783545255075
 1.117776876821525
 2.470121871347117
 2.5
u: 5-element Array{Array{Float64,1},1}:
 [1000.0, 0.0, 0.0]
 [1122.192002548497, 0.0, 0.0]
 [1748.727601815643, 0.0, 0.0]
 [3438.588077255191, 0.0, 0.0]
 [3490.342988172429, 0.0, 0.0]

julia> soln2
retcode: Success
Interpolation: Automatic order switching interpolation
t: 57-element Array{Float64,1}:
  2.5
...
  6.345783848634277
  ⋮
  7.954813105553676
...
 20.0
u: 57-element Array{Array{Float64,1},1}:
 [3490.342988172429, 0.0, 1.0e8]
...
 [3208.560197325081, 0.0007928568460220974, 0.8821627287560089]
 ⋮
 [7173.092759205297, 1.095531236362228e-6, 0.0007379875987002946]
...

julia> 

```

How can I merge them properly?  
Thank you

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 9, 2020, 12:46pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520/2 "2020-12-09T12:46:15Z")

</div>

You don’t seem to only have two arrays, but two more complicated objects that seem to be a solution to some problem. What do you mean when you describe these as “array”?

Also, when asking questions, it is generally a good idea to give a concrete example of what you want. That avoids the difficulty in describing the operation in natural language. For example, if you have the two arrays `[1,2,3]` and `[4,5,6]`, what does “merging” them mean? What is the final result you want?

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [December 9, 2020, 1:47pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520/3 "2020-12-09T13:47:04Z")

</div>

You are right, this is the solution of a differential equation. I gather that it is an array because Julia tells that it is a `5-element Array{Float64,1}` and `5-element Array{Array{Float64,1},1}`. I understand there is a first element that is a vector (t) and a second element (u) that is a vector of vectors (each element is an array of three values).  
I simply wanted to concatenate the t vectors of the two arrays together, and the u arrays together…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 9, 2020, 3:07pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520/4 "2020-12-09T15:07:15Z")

</div>

> [@Luigi\_Marongiu](#):
>
> concatenate

`vcat`?

---

<div class="post-metadata">

**Author:** ![cojua8](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cojua8/32/11882_2.png) [@cojua8](https://discourse.julialang.org/u/cojua8)\
**Post date:** [December 9, 2020, 7:39pm UTC](https://discourse.julialang.org/t/how-to-merge-arrays-in-julia/51520/5 "2020-12-09T19:39:34Z")

</div>

> [@Luigi\_Marongiu](#):
>
> ```julia
> julia> soln1
> retcode: Success
> Interpolation: Automatic order switching interpolation
> t: 5-element Array{Float64,1}:
> 0.0
> 0.23056783545255075
> 1.117776876821525
> 2.470121871347117
> 2.5
> u: 5-element Array{Array{Float64,1},1}:
> [1000.0, 0.0, 0.0]
> [1122.192002548497, 0.0, 0.0]
> [1748.727601815643, 0.0, 0.0]
> [3438.588077255191, 0.0, 0.0]
> [3490.342988172429, 0.0, 0.0]
> 
> ```

I see you have an object (whose `Type` can be checked with `typeof(soln1)`).

To check its members, in the REPL you can type

```julia
julia> soln1.

```

and then tab twice to check its fields.

As an example, let’s say that `soln1.t` returns array `t`. Then to combine your arrays into a third, you just do:

```julia
julia> vcat(soln1.t, soln2.t)

```
