Matlab error: Index exceeds matrix dimensions

前端 未结 1 1270
情歌与酒
情歌与酒 2020-12-22 03:09

I\'m trying to perform STFT on an audio file. I need to get the fft of each window.

I used the follwing code.

[wave,fs] = wavread(\'40.wav\'); 
w_len         


        
相关标签:
1条回答
  • 2020-12-22 04:01

    As the error message says, you are trying to access a position in wave tat does not exist.

    See this example:

    a    = rand(7,1);
    step = 4;
    
    1:step:7
    ans =
         1     5
    

    when v = 5, you will try to access position v:v+step, i.e. 5 to 9, but a is only defined up to 7 elements.

    In your case, wave is defined up to length(wave), but on the last iteration you will go out of bounds.

    To avoid it, on approach would be to sample the end sequences and subtract the length of the sequence:

    pos = (1+w_length:w_length:length(wave))-w_length
    for v = pos
    % do stuff
    end
    

    However, you will be left with some unprocessed part which you will have to do outside of the loop as last iteration.

    0 讨论(0)
提交回复
热议问题