I get the error 'Subscript indices must either be real positive integers or logicals'? Please help!

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');

Risposte (1)

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);

4 Commenti

Thank you so much for the suggestion. However, now it stops at the next line of "y(startPtr:endPtr) = y(startPtr:endPtr) + x1';".
The error message is now "Error using + Matrix dimensions must agree.
Error in songvolution (line 25) y(startPtr:endPtr) = y(startPtr:endPtr) + x1';"
I'm overwhelmed...
The error is that y(startPtr:endPtr) and x1' must be exactly the same size in order for them to be added together. They are obviously not the same size, so you are getting this error message.
I have no idea what the code should be doing, so if you need help understanding it then I suggest that you ask the person who wrote it.
Alternatively if you tell us exactly what you need to achieve, then we can help you to write efficient code to achieve your aims.
Thank you so much for your reply. The problem was one of mp3 files had a different sample rate.
I am trying to extract some portions(about 1 second) from a lot of mp3 files(about 1000) then put them in order to create a mix of an audio file. The code extracts in the middle of audio file. However, it would be great if it extracts the beginning of the chorus part. I think the chorus part has the peak or maximum energy in the song and I've been figuring out but I couldn't and I really need help... If you can help me that would be really great.. Thank you so much for your help. I really appreciate it.

Accedi per commentare.

Categorie

Prodotti

Richiesto:

il 14 Nov 2015

Modificato:

il 19 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by