# ERROR: LoadError: MethodError: no method matching ./(::#sigma2#1, ::Array{Float64,2})

**URL:** <https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839>\
**Category:** General Usage\
**Created:** [March 23, 2017, 5:35pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839 "2017-03-23T17:35:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 23, 2017, 5:35pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/1 "2017-03-23T17:35:40Z")

</div>

What is wrong with the following code?

```julia
for i=1:length(m)	# loop over the various cluster sizes
  for k=1:N-2*m[i]	# implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
    sigma2(i,:) = sigma2(i,:) + (theta(k+2*m[i],:) - 2*theta(k+m[i],:) + theta(k,:)).^2
    end
end

sigma2 = sigma2./repmat((2*T.^2.*(N-2*m)),1,M)

```

I get the error message

ERROR: LoadError: MethodError: no method matching ./(::#sigma2#1, ::Array{Float64,2})  
Closest candidates are:  
./{T}(!Matched::Number, ::AbstractArray{T,N}) at arraymath.jl:67  
./(!Matched::SparseMatrixCSC{Tv,Ti\<:Integer}, ::Array{T,N}) at sparse/sparsematrix.jl:1724  
./(!Matched::AbstractArray{T,N}, ::AbstractArray{T,N}) at broadcast.jl:302

---

<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:** [March 23, 2017, 5:45pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/2 "2017-03-23T17:45:50Z")

</div>

This is julia and not MATLAB so you should use `[]` for indexing.

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 23, 2017, 5:59pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/3 "2017-03-23T17:59:10Z")

</div>

Right, thanks

However,

```julia
for i=1:length(m)	# loop over the various cluster sizes
  for k=1:N-2*m[i]	# implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
    sigma2[i,:] = sigma2[i,:] + (theta[k+2*m[i],:] - 2*theta[k+m[i],:] + theta[k,:]).^2
    end
end

```

throws

ERROR: LoadError: ArgumentError: invalid index: 3.0  
in macro expansion at ./multidimensional.jl:294 [inlined]  
in \_unsafe\_getindex at ./multidimensional.jl:291 [inlined]  
in \_getindex at ./multidimensional.jl:271 [inlined]  
in getindex at ./abstractarray.jl:760 [inlined]

---

<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:** [March 23, 2017, 6:15pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/4 "2017-03-23T18:15:44Z")

</div>

[http://docs.julialang.org/en/latest/manual/noteworthy-differences.html#Noteworthy-differences-from-MATLAB-1](http://docs.julialang.org/en/latest/manual/noteworthy-differences.html#Noteworthy-differences-from-MATLAB-1)

---

<div class="post-metadata">

**Author:** ![ohsonice](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@ohsonice](https://discourse.julialang.org/u/ohsonice)\
**Post date:** [March 23, 2017, 6:17pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/5 "2017-03-23T18:17:38Z")

</div>

Looks like you you’re indexing an Array with an Float (i.e: 1.0, 2.1) when what you want is an Integer (i.e: 1, 2, etc)

Some documentation on that: [http://docs.julialang.org/en/stable/manual/integers-and-floating-point-numbers](http://docs.julialang.org/en/stable/manual/integers-and-floating-point-numbers).

what is the output of:

> typeof(m)

---

<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:** [March 23, 2017, 6:17pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/6 "2017-03-23T18:17:52Z")

</div>

Hmmm, somehow it’s not mentioned there. You cannot index an array with floating point numbers. Without the full code it’s impossible to tell what you are doing but it’s likely that `m` is not an integer array.

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 23, 2017, 7:28pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/7 "2017-03-23T19:28:54Z")

</div>

typeof(m) Array{Float64,2}

m= [1.0 4.0 16.0 64.0 256.0]

I think m is meant to be intergers

(and yes, the code is an attempt to port from MATLAB)

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 23, 2017, 7:45pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/8 "2017-03-23T19:45:39Z")

</div>

Here is the whole code:

```julia
# *********FUNCTION DEFINITIONS********

function allan(omega,fs,pts)
# omega = sample data. Unit should be in radians/sec
# fs = sample frequency
# pts = number of logarithmically spaced points 

# Determine the size of the output data set 
(N,M) = size(omega)

# determine largest bin size
n = 2.^(0:floor(log2(N/2)))'

# Select the last element of the vector (the largest bin size)
maxN = n[end]
endLogInc = log10(maxN)

# m is chosen arbitrarily
m = unique(ceil(logspace(0,endLogInc,pts)))' # create log spaced vector average factor 

# t0 = sample interval
t0 = 1/fs	

# T = length of time of each cluster (tau)
T = m*t0	

# Integrate samples over time to obtain output angle θ
theta = cumsum(omega)/fs

# Create an array of dimensions (cluster periods) X ( No. of variables)
sigma2 = zeros(length(T),M)

for i=1:length(m)	# loop over the various cluster sizes
  for k=1:N-2*m[i]	# implements the summation in the Allan Variance equation (eqn. 8 in ref 1.
    sigma2[i,:] = sigma2[i,:] + (theta[k+2*m[i],:] - 2*theta[k+m[i],:] + theta[k,:]).^2
    end
end

sigma2 = sigma2./repmat((2*T.^2.*(N-2*m)),1,M)
sigma = sqrt(sigma2) # The Allan Deviation 

return sigma
end

# *********END OF FUNCTION DEFINITIONS*****

# *********MAIN PROGRAM********

file=open("sensor_data.dat", "r")
data = readdlm(file,' ')
close(file)

fs = 50 # 50 Hz Sample rate
pts = 5 # No. of logarithmically spaced points

Sigma = allan(data, fs, pts)

println("Sigma= ", Sigma)

# *********END OF MAIN PROGRAM********

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 23, 2017, 10:08pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/9 "2017-03-23T22:08:33Z")

</div>

In Julia, the `ceil()` function rounds upward but does not convert the result to an integer:

```julia
julia> ceil([1.5, 1.6])
2-element Array{Float64,1}:
 2.0
 2.0

```

to get an integer, you can instead do:

```julia
julia> ceil(Int, [1.5, 1.6])
2-element Array{Int64,1}:
 2
 2

```

Many Julia functions take a type as their first parameter like this:

```julia
julia> zeros(Int, 2, 2)
2×2 Array{Int64,2}:
 0 0
 0 0

julia> rand(Int, 2, 2)
2×2 Array{Int64,2}:
 4442662091972791053 1315597098779686556
  -67815619393417912 8004661696684852519

```

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 24, 2017, 7:57am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/10 "2017-03-24T07:57:02Z")

</div>

Thank you! That did the trick

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [March 24, 2017, 8:39am UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/11 "2017-03-24T08:39:38Z")

</div>

I have one last problem,

What is the essence of this expression in MATLAB ?

`sigma2 = sigma2./repmat((2*T.^2.*(N-2*m)),1,M)`

It seems like the syntax would work in Julia as well. But when I execute this line I get the error:

> ERROR: LoadError: DimensionMismatch(“arrays could not be broadcast to a common size”)

The nominator and denominator have the following properties

> typeof(sigma2)= Array{Float64,2}

> typeof(repmat((2_T.^2._(N-2\*m)),1,M))= Array{Float64,2}

> sizeof(sigma2)= 440

> sizeof(repmat((2_T.^2._(N-2\*m)),1,M))= 440

> sigma2= [13.2508 11.556 8.442 46.3152 44.0672 28.2076 94.5208 125.92 924.021 5.8616 0.2104; 45.6592 34.5664 30.036 253.931 225.472 107.641 438.842 586.606 4502.78 50.814 1.6468; 184.576 110.935 166.279 1053.09 1225.07 413.82 2375.03 2487.8 32825.9 706.581 12.8648; 2082.21 1868.43 10988.8 4948.69 4457.05 1274.72 10652.1 6671.7 63628.1 7758.94 199.189; 1.05607e5 33235.0 37830.9 814.318 1968.7 7961.28 1.00828e5 39766.8 59889.7 7902.17 963.78]

> repmat((2_T.^2._(N-2\*m)),1,M)= [0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9 0.5888 9.344 144.589 1998.85 11848.9]

---

<div class="post-metadata">

**Author:** ![ohsonice](https://avatars.discourse-cdn.com/v4/letter/o/d6d6ee/32.png) [@ohsonice](https://discourse.julialang.org/u/ohsonice)\
**Post date:** [March 25, 2017, 5:03pm UTC](https://discourse.julialang.org/t/error-loaderror-methoderror-no-method-matching-sigma2-1-array-float64-2/2839/12 "2017-03-25T17:03:38Z")

</div>

Hm, looks like those arrays are not actually the same size.

`sizeof` and `size` are not the same commands, see below documentation for both:

> help?\> sizeof  
> search: sizeof

> sizeof(T)

> Size, in bytes, of the canonical binary representation of the given DataType T, if any.

> sizeof(s::AbstractString)

> The number of bytes in string s.

and:

> help?\> size  
> search: size sizeof sizehint! Csize\_t resize! filesize Cssize\_t trailingsize serialize Serializer deserialize displaysize

> size(A::AbstractArray, [dim…])

> Returns a tuple containing the dimensions of A. Optionally you can specify the dimension(s) you want the length of, and get  
> the length of that dimension, or a tuple of the lengths of dimensions you asked for.

> julia\> A = ones(2,3,4);

> julia\> size(A, 2)  
> 3

> julia\> size(A,3,2)  
> (4,3)

Showing the output of `size` should help you debug this problem.
