0

I am trying to read a WAV file in MATLAB and truncate it to 1 sec.

Here is the code I am trying right now, taken from:

http://www.mathworks.com/matlabcentral/answers/596-truncating-wav-files

[x,fs,k] = wavread(FileNames); Y = x(n:n+fs-1, :);

This however gives me the following error:

Subscript indices must either be real positive integers or logicals. Error in Test (line 13) Y = x(n:n+fs-1, :);

How can I fix this and how I can do the truncation?

Kanishka Ganguly
  • 1,252
  • 4
  • 18
  • 38
  • Have you checked what is `n` and `fs`? What is the output of `n:n+fs-1`? Probably you could find the answer by yourself. – yuk May 08 '14 at 20:40
  • For the [generic solution to this problem](http://stackoverflow.com/a/20054048/983722), see [this question](http://stackoverflow.com/q/20054047/983722). – Dennis Jaheruddin May 26 '14 at 15:35

1 Answers1

0

Make sure n is at least 1. Also make sure it's not exceeding length of x. It can't be that hard. Just see the indices

akhilc
  • 181
  • 4
  • 19