# Concatenating vectors

**URL:** <https://discourse.julialang.org/t/concatenating-vectors/22272>\
**Category:** New to Julia\
**Created:** [March 24, 2019, 2:13pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272 "2019-03-24T14:13:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [March 24, 2019, 2:13pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/1 "2019-03-24T14:13:05Z")

</div>

Hello colleagues,  
I have a little question. I want to build a matrix in Julia 7.0, where is a concatenation of several vectors of same length. I use the code:  
A = rand(10,10)  
B = %a empty matrix  
for i=1:2:10  
B = [B;A[i,:]] %B is the matrix whose line i is from A, where i is odd  
end  
In Julia 0.6.4, the above code is ok. But in version 7.0 not run. The error is:  
ArgumentError: number of columns of each array must match (got (1, 10))  
\_typed\_vcat(::Type{Any},

Anyone could help me?

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [March 24, 2019, 3:04pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/2 "2019-03-24T15:04:25Z")

</div>

To fix the dimension mismatch, you can initialize `B` with `zeros(0,10)` (so it’s 0 rows and 10 columns), and use `A[i:i,:]` in place of `A[i,:]` inside the loop (to get a 1×10 row vector).  
But it’s easier to just do

```julia
B = A[1:2:10,:]

```

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [March 24, 2019, 3:12pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/3 "2019-03-24T15:12:17Z")

</div>

Thank you very much, colleague!!!

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 24, 2019, 3:34pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/4 "2019-03-24T15:34:55Z")

</div>

> [@angeloaliano1](#):
>
> A = rand(10,10)  
> B = %a empty matrix  
> for i=1:2:10  
> B = [B;A[i,:]] %B is the matrix whose line i is from A, where i is odd  
> end

There’s something very strange about your code snippet, btw. Your comments use `%` which should not work, since the julia character for comments are `#`, and the assignment to `B` has some weird character that I cannot even copy, it seems to be an image of some sort.

It’s great that you got the help you needed, but for future reference, it is preferable if you can provide a full example that can be copied and run, and also that you wrap your example code in triple backticks, as explained here: [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![angeloaliano1](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Post date:** [March 24, 2019, 6:07pm UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/5 "2019-03-24T18:07:39Z")

</div>

Thank you very much for attention.

---

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [March 25, 2019, 5:01am UTC](https://discourse.julialang.org/t/concatenating-vectors/22272/6 "2019-03-25T05:01:56Z")

</div>

> [@DNF](#):
>
> some weird character that I cannot even copy

A bit OT, but it’s an empty check box (code “`[]`” interpreted as markdown):

```julia
[]
[x]

```

produces:
