I get the error 'Subscript indices must either be real positive integers or logicals'? Please help!
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to take short parts of hundreds of mp3 files and mix them automatically. It works until about 43rd song but after that I get the error message at the line of "x = x(end-fs*excerptDur:end);". I can't find the solution. Please help.
---------------------------------------------
filenames = dir('*.mp3');
clc
analysis.dur = zeros(1, length(filenames));
fs = 44100;
totalDur = 100;
y = zeros(1, fs*totalDur);
excerptDur = 2;
hop = excerptDur/4*fs;
startPtr = 1;
endPtr = excerptDur*fs+1;
warning off
for i=1:length(filenames)
[x, fs] = audioread(filenames(i).name);
x = mean(x');
x = x(1:end/10);
x = x(end-fs*excerptDur:end);
analysis.dur(i) = round(length(x)/fs*60);
x1 = hann(length(x)).*x';
y(startPtr:endPtr) = y(startPtr:endPtr) + x1';
startPtr = startPtr + hop;
endPtr = endPtr + hop;
disp(filenames(i).name)
end
y = y(1:endPtr);
warning on
sound(y, fs)
spectrogram(y,2048,2000,'yaxis');
0 个评论
回答(1 个)
Stephen23
2015-11-14
Your index is probably going to zero or negative. Consider if fs*exceptDur is larger than the length of x
x = x(end-fs*excerptDur:end);
then it is equivalent to
x = x(-N:end);
for some whole number N. You could avoid this by using max:
x = x(max(1,end-fs*excerptDur):end);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!