# Output matrix in last (t-1) generation: normal; Indexing the same matrix in this generation: NaNs in the (t-1) column

**URL:** <https://discourse.julialang.org/t/output-matrix-in-last-t-1-generation-normal-indexing-the-same-matrix-in-this-generation-nans-in-the-t-1-column/35059>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 24, 2020, 12:27am UTC](https://discourse.julialang.org/t/output-matrix-in-last-t-1-generation-normal-indexing-the-same-matrix-in-this-generation-nans-in-the-t-1-column/35059 "2020-02-24T00:27:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [February 24, 2020, 12:27am UTC](https://discourse.julialang.org/t/output-matrix-in-last-t-1-generation-normal-indexing-the-same-matrix-in-this-generation-nans-in-the-t-1-column/35059/1 "2020-02-24T00:27:25Z")

</div>

The only part of this function differring from my previous functional one is adding a variable to be calculated in each generation.

```julia
NDeme=0.5(Nmax+Nmin)+0.5(Nmax+Nmin)*sin(2pi*t/period)
#period=12 genetation in setting
#oscillating population size

```

As NDeme can be 0 at 9th (9+12n) generation, I set 0 to be replaced by 1 for avoiding NaNs, so it gets the normal output at 9th and move on to error in 22th generation. The end of the shared matrix of the deme in 21th generation doesn’t contain any NaNs.

```julia
generation############21
deme#####5
nan in x CartesianIndex{2}[] #beginning of this turn
nan in x_end of nDemes loop CartesianIndex{2}[] #end of this turn
 #observation: no NaNs contained)

```

However, the extracted matrix at the beginnig of 22th generation contains NaNs in the column corresponding to the 21st generation.

```julia
generation############22
#deme1 to 4 are all fine.

deme#####5
nan in x CartesianIndex{2}[CartesianIndex(3, 21), CartesianIndex(4, 21), CartesianIndex(5, 21), CartesianIndex(6, 21), CartesianIndex(7, 21), CartesianIndex(8, 21), CartesianIndex(9, 21), CartesianIndex(10, 21), CartesianIndex(11, 21), CartesianIndex(12, 21), CartesianIndex(13, 21), CartesianIndex(14, 21), CartesianIndex(15, 21), CartesianIndex(16, 21), CartesianIndex(17, 21), CartesianIndex(18, 21), 
CartesianIndex(19, 21), CartesianIndex(20, 21)]
  #all NaN in the column corresponding to 21th generation
x [0.0, 0.0, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]

```

I reboost my laptop and atom several times but problem remains. The error information: often in 10th generation, and sometimes 22th, 34th which are the time points when NDeme supposed to be zero but set to 1.

I got confused by the converse testification between outputs in last generation and input in this generation. Could anyone give a hint? Is this the problem of algorithm (the variable, or replacing 0 with 1) or else(some unknown setting)?

---

<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:** [February 24, 2020, 6:35am UTC](https://discourse.julialang.org/t/output-matrix-in-last-t-1-generation-normal-indexing-the-same-matrix-in-this-generation-nans-in-the-t-1-column/35059/2 "2020-02-24T06:35:30Z")

</div>

I think there is a lot of context missing here, please post a self-contained MWE.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [February 24, 2020, 2:58pm UTC](https://discourse.julialang.org/t/output-matrix-in-last-t-1-generation-normal-indexing-the-same-matrix-in-this-generation-nans-in-the-t-1-column/35059/3 "2020-02-24T14:58:29Z")

</div>

During the process of making minimum working example, I found it’s due to the lowest point from this `sin()` function. After migration, the NDeme (sometimes serve as denominator) could be 0, which leads to NaNs in output.
