I get the error 'Subscript indices must either be real positive integers or logicals'? Please help!
Show older comments
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');
Answers (1)
Stephen23
on 14 Nov 2015
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 Comments
JAE KANG JANG
on 14 Nov 2015
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.
JAE KANG JANG
on 19 Nov 2015
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!