ArgumentError: invalid index: 1.0 of type Float64

Hi all,
I get that error when I’m trying to run this code:

filename="channelABCD_2021-12-31_10-20-45.wav"
y,Fs = wavread(filename)
Y=y[1:3.6e7,2]

ERROR: ArgumentError: invalid index: 1.0 of type Float64

Thank you for your help!

Assuming y is a 2 dimensional array, you are trying to get the components using an index range of floating point numbers rather than integers (because 3.6e7 is a Float64, the whole index range is converted to a list of Float64 numbers, starting with 1.0 and not the integer 1).
I believe you can fix this by using 1:(36x10^6) instead.

2 Likes

I think you mean 1:(36*10^6)? (Interestingly enough, you can make 1:(36x10^6) work if you define x10 = 10.)

7 Likes

Good catch (probably shouldn’t type code on a phone.)