# Creating a 2x100 matrix with linspace

**URL:** <https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 6, 2017, 12:26am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277 "2017-10-06T00:26:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffR1992](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@JeffR1992](https://discourse.julialang.org/u/JeffR1992)\
**Post date:** [October 6, 2017, 12:26am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277/1 "2017-10-06T00:26:58Z")

</div>

The following code produces a 2x100 matrix in MATLAB:

> x0 = 0;  
> y0 = 0;  
> xf = 100;  
> yf = 200;  
> r0 = [x0; y0];  
> rf = [xf; yf];  
> r1 = [linspace(r0(1),rf(1),N); linspace(r0(2),rf(2),N)];

Trying the same thing in Julia using:

> r1 = [linspace(r0[1],rf[1],N); linspace(r0[2],rf[2],N)];

And checking size(r1), I get an answer of (200,) which is a 1D array. How would I be able to replicate MATLAB’s results to produce a 2x100 matrix? Any help would be great, thanks very much.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [October 6, 2017, 12:41am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277/2 "2017-10-06T00:41:00Z")

</div>

> [@JeffR1992](#):
>
> [linspace(r0[1],rf[1],N); linspace(r0[2],rf[2],N)]

`[a; b]` is vcat, which combine the two arrays in the first dimension, `[a b]` is hcat which combine the two arrays in the second dimension.  
`linspace` returns a (vertical) vector so if you want to combine them in the other dimension you should use hcat so `[linspace(r0[1],rf[1],N) linspace(r0[2],rf[2],N)]` should work. (The result size will be `(100, 2)`)

---

<div class="post-metadata">

**Author:** ![PabloZubieta](https://avatars.discourse-cdn.com/v4/letter/p/ee7513/32.png) [@PabloZubieta](https://discourse.julialang.org/u/PabloZubieta)\
**Post date:** [October 6, 2017, 1:41am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277/3 "2017-10-06T01:41:44Z")

</div>

As Yichao already said, `linspace` returns a vector. If you want a `2x100` `Array` you can use

```julia
[linspace(r0[1],rf[1],N)'; linspace(r0[2],rf[2],N)']

```

---

<div class="post-metadata">

**Author:** ![JeffR1992](https://avatars.discourse-cdn.com/v4/letter/j/58f4c7/32.png) [@JeffR1992](https://discourse.julialang.org/u/JeffR1992)\
**Post date:** [October 6, 2017, 2:43am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277/4 "2017-10-06T02:43:56Z")

</div>

Thanks pabloferz, that did the trick

---

<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:** [October 6, 2017, 8:27am UTC](https://discourse.julialang.org/t/creating-a-2x100-matrix-with-linspace/6277/5 "2017-10-06T08:27:06Z")

</div>

A side note: It is actually Matlab that is acting weird here. Matlab is supposed to be column-major, but still, functions like `linspace` and `1:10` return row vectors. Very odd, and frequently quite annoying.
