# MethodError: no method matching -(::LinearAlgebra

**URL:** <https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477>\
**Category:** General Usage\
**Created:** [July 29, 2021, 6:44am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477 "2021-07-29T06:44:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kip0d](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kip0d](https://discourse.julialang.org/u/kip0d)\
**Post date:** [July 29, 2021, 6:44am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477/1 "2021-07-29T06:44:12Z")

</div>

Can you explain please what is wrong with my code?

```julia
idxWindow = (-floor((N-1)/2):floor(N/2))'
for indm = 1:M
    FD = distvec_samp[indm]
    if FD .> 0
        IntegerD = floor(FD)
        FDGal = FD - IntegerD
        hIdeal = (k) -> sinc[k-FDGal]
        hApprox = hIdeal(idxWindow)
        Sig_fd[indm,:] = filter(hApprox,1,[Sig[IntegerD+1:end],zeros(1,IntegerD)])
    else()
        IntegerD = ceil(FD)
        FDGal = FD - IntegerD
        hIdeal(k) = sinc[k-FDGal] # <------ The problem is here
        hApprox = hIdeal(idxWindow) # <------- The problem is here
        Sig_fd[indm,:] = filter(hApprox,1,[zeros(1,abs(IntegerD)),Sig[1:end+IntegerD]])
    end
    NoiseSigma = sqrt(var(Sig_fd[indm,139000:140300])*10^(-SNR/10)); # Calculated an APPROXIMATED noise sigma
    Sig_fd[indm,:] = Sig_fd[indm,:] + NoiseSigma*randn(size(Sig_fd[indm,:]))
end

```

The error:

```julia
ERROR: LoadError: MethodError: no method matching -(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Float64)
Closest candidates are:
  -(!Matched::Float64, ::Float64) at float.jl:397
  -(!Matched::Complex{Bool}, ::Real) at complex.jl:298
  -(!Matched::Missing, ::Number) at missing.jl:93
  ...
Stacktrace:
 [1] (::getfield(Main, Symbol("#hIdeal#5")))(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at /bfv1.jl:191
 [2] top-level scope at /bfv1.jl:192
 [3] include at ./boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at ./loading.jl:1044
 [5] include(::Module, ::String) at ./sysimg.jl:29
 [6] exec_options(::Base.JLOptions) at ./client.jl:266
 [7] _start() at ./client.jl:425
in expression starting at /bfv1.jl:178

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 29, 2021, 7:19am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477/2 "2021-07-29T07:19:16Z")

</div>

It’s a little hard to tell because your code is not an MWE - none of your variables are defined anywhere, and there’s a lot of most likely irrelevant stuff in there as well. Have a look at [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) to get some ideas on how to most effectively ask for help here.

That said, you method error is (reasonably) clear I would say:

```julia
no method matching -(::LinearAlgebra.Adjoint{Float64,StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Float64)

```

It’s slightly more convoluted then it could be because your `FD` (presumably) is an adjoint rather than a regular matrix, but it tells you that you can’t subtract an integer from a matrix. The error is a bit easier to digest if you have a “regular” matrix:

```julia
julia> matrix = rand(3, 3)
3×3 Matrix{Float64}:
 0.936169 0.367046 0.109481
 0.763018 0.0366246 0.933463
 0.748903 0.128593 0.47728

julia> matrix - 1
ERROR: MethodError: no method matching -(::Matrix{Float64}, ::Int64)
For element-wise subtraction, use broadcasting with dot syntax: array .- scalar

```

And it even tells you what you should be doing if you are looking to subtract that scalar from every element of your matrix!

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [July 29, 2021, 7:23am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477/3 "2021-07-29T07:23:30Z")

</div>

> [@kip0d](#):
>
> ` hIdeal(k) = sinc[k-FDGal] # <------ The problem is here`

From the error message it looks like `k` is some kind of array. You cannot subtract a number (`FDGal`) from an array (`k`), you need to use broadcasting to do it element-wise, i.e., `k .- FDGal` (with `.-` instead of `-`).

---

<div class="post-metadata">

**Author:** ![kip0d](https://avatars.discourse-cdn.com/v4/letter/k/71c47a/32.png) [@kip0d](https://discourse.julialang.org/u/kip0d)\
**Post date:** [December 13, 2021, 9:24am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477/4 "2021-12-13T09:24:57Z")

</div>

Thank you, I changed to:

> hIdeal = (k) → sinc.(k.-FDGal)  
> But now I get:  
> ERROR: MethodError: no method matching zeros(::Int64, ::Float64)  
> on the this line:  
> Sig\_fd[indm,:] = filt.(hApprox,1,[zeros(1,abs(IntegerD)),Sig[1:end+IntegerD]])

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [December 13, 2021, 10:02am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-linearalgebra/65477/5 "2021-12-13T10:02:32Z")

</div>

It seems like you are trying to call `zeros` using a float, and there is not method defining how to do that (as expected). Have you checked what type `IntegerD` has, it seems like it might be a float.

Checking the docstring for `ceil` we get

```julia
help?> ceil
search: ceil replacefield! ProcessFailedException InteractiveUtils

  ceil([T,] x)
  ceil(x; digits::Integer= [, base = 10])
  ceil(x; sigdigits::Integer= [, base = 10])

  ceil(x) returns the nearest integral value of the same type as x that is
  greater than or equal to x.

  ceil(T, x) converts the result to type T, throwing an InexactError if the
  value is not representable.

```

where the last row is probably interesting for you.
