I have tried hard to write a minimalist sample code of the situation I am facing,
but fail :-(.
Part of my data is stored in a MAT-file (generated by Julia package MAT).
After reading back the vector eis_frequency_Shunt
which is nested inside this MAT,
the result is of type Vector(Any)
. In the next step I take out one element of the
vector and the result is again a vector (Vector{Any}
), holding one element.
Now it happens that the function that takes this one-element vector fails to execute,
because the compiler complains about a format mismatch (see below).
I had to use the notation []
to make it possible to run my script,
the annoying thing was, it took a while for me, to figure out the root-cause of the
crash.
Here a snippet of my code:
[...]
_frequ_Shunt = eis_frequency_Shunt[indx_in_FFT_results]
_A, _B = MyLibCalibrationAmplPhase(_frequ_Shunt, B, C, D, E)
And here the definition of the function:
function MyLibCalibrationAmplPhase(_frequency::Real, _data_pts::Vector{<:Number},
_sampl_rate::Real, _num_periods::Int=10, _LSQ_method::Int=0)
[...]
end
And here the error message (the first two lines are debugging output):
DBG: _frequ_Shunt, type: Vector{Any}, size: (1,)
DBG: eis_frequency_Shunt, type: Vector{Any}, size: (46,)
[...]
ERROR: MethodError: no method matching MyLibCalibrationAmplPhase(::Vector{Any}, ::Vector{Float64}, ::Float64, ::Int64, ::Int64)
Closest candidates are:
MyLibCalibrationAmplPhase(::Real, ::Vector{<:Number}, ::Real, ::Int64, ::Int64) at C:\data\git_repos\hycenta_julia\Julia_Modules\SignalAnalysis\HyCentaHarmonicSignalAnalysis.jl:148
MyLibCalibrationAmplPhase(::Real, ::Vector{<:Number}, ::Real, ::Int64) at C:\data\git_repos\hycenta_julia\Julia_Modules\SignalAnalysis\HyCentaHarmonicSignalAnalysis.jl:148
MyLibCalibrationAmplPhase(::Real, ::Vector{<:Number}, ::Real) at C:\data\git_repos\hycenta_julia\Julia_Modules\SignalAnalysis\HyCentaHarmonicSignalAnalysis.jl:148
I can avoid this error by adding empty squared brackets: []
:
_frequ_Shunt = eis_frequency_Shunt[indx_in_FFT_results][]
This was the trigger to think about, how to improve my function,
to handle this strange situation.