# Problem allocating vector components

**URL:** <https://discourse.julialang.org/t/problem-allocating-vector-components/57756>\
**Category:** New to Julia\
**Tags:** memory-allocation\
**Created:** [March 22, 2021, 10:50pm UTC](https://discourse.julialang.org/t/problem-allocating-vector-components/57756 "2021-03-22T22:50:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leopdsf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leopdsf/32/31008_2.png) [@leopdsf](https://discourse.julialang.org/u/leopdsf)\
**Post date:** [March 22, 2021, 10:50pm UTC](https://discourse.julialang.org/t/problem-allocating-vector-components/57756/1 "2021-03-22T22:50:14Z")

</div>

Hello, there!  
I’m studying the spacing s between eigenvalues of 2\times2 matrices. My code is the following (some description lies in the comments):

```julia
using Distributions
using LinearAlgebra

d1 = Normal(0.0,1)
d2 = Normal(0.0,1/2)
N = 10 #size of the ensemble

for k in 1:N #loop that generates the N sets of eigenvalues
        
    for i in 1:2 #generating the random gaussian matrix
        for j in 1:2
            if i == j B[i,j] = rand(d1)
            end
        end
    end
    B[1,2] = B[2,1] = rand(d2)

    λ = eigvals(B) #calculating the eigenvalues
    s[k] = abs(λ[1] - λ[2]) #calculating the spacement between them
end

```

I’m trying to storage the information about the spacement of the N matrices at the ensemble in the vector s, wich may have N components, but I receive the following error when I try to run:

```julia
MethodError: no method matching setindex!(::Float64, ::Float64, ::Int64)

```

Someone knows what is wrong?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 22, 2021, 11:18pm UTC](https://discourse.julialang.org/t/problem-allocating-vector-components/57756/2 "2021-03-22T23:18:56Z")

</div>

I can’t reproduce the error here. In your code `s` is not defined, but even if I define it, I do not get any error.

---

<div class="post-metadata">

**Author:** ![leopdsf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leopdsf/32/31008_2.png) [@leopdsf](https://discourse.julialang.org/u/leopdsf)\
**Post date:** [March 22, 2021, 11:43pm UTC](https://discourse.julialang.org/t/problem-allocating-vector-components/57756/3 "2021-03-22T23:43:25Z")

</div>

Yeah, this is strange. I restarted juno, recompiled and it worked. Thank tou very much! 😃
