Matlab error in vowel extraction code, would you please help?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Please I need some explanation for why my matlab code is behaving so badly. I absolutely do not see any mistakes in my code, but still matlab outputs this old *"??? Index exceeds matrix dimensions". *I am extremely frustrated. PLEASE HELP. I am really frustrated. I am almost mad. I have been working on this code for so long, and I absolutely think that the problem is with matlab, not my code, really. Below is my code. It is a function that takes as input a sound file.
PLEASE HELP.
THANKS.
function U=Extract_U_in_July(filename)
s=wavread(filename);
s=s./sum(abs(s));
L=length(s);
n=ceil(L/60);
k=L/n;
for i=1:floor(k)
p=1;
for aa=(i-1)*n+1:L-(abs(k-i-1))*n
m(p)=s(aa);
if aa==i*n
Norm(i)=sum(abs(m))/length(m);
end
p=p+1;
end
end
p=1;
for oo=round(k)*n+1:L
m(p)=s(oo);
if oo==L
Norm(i+1)=sum(abs(m))/length(m);
end
p=p+1;
end
Norm=Norm./max(Norm);
ZerosOnes=Norm>Norm(1);
Lenz=length(ZerosOnes);
kk=1;
ii=1;
store=[];
while ii<=Lenz
for l=ii:Lenz
if ZerosOnes(l)==1;
store(kk)=l;
break;
end
end
kk=kk+1;
for ii=l:Lenz
if ZerosOnes(ii)==0
store(kk)=ii-1;
break;
end
end
kk=kk+1;
ii=ii+1;
end
store=store(store~=0)
Ls=length(store);
for jj=1:floor(Ls/2)
if store(jj*2)-store(jj*2-1)==0
store([store(1,:)==store(1,jj*2)])=[];
store([store(1,:)==store(1,jj*2-1)])=[];
end
end
j=1;
for x=1:length(store)/2
count(j)=store(x*2)-store(x*2-1)+1;
j=j+1;
end
IntervalLength=max(count);
for x=1:length(store)/2
if store(x*2)-store(x*2-1)+1==IntervalLength
starting=store(x*2-1);
ending=store(x*2);
end
end
Interval=Norm(starting:ending);
Upeak=findpeaks(Interval,'NPEAKS',1);
plot(Interval)
end
Error in ==> Extract_U_in_July at 60 if store(jj*2)-store(jj*2-1)==0
0 commentaires
Réponse acceptée
Walter Roberson
le 3 Fév 2013
Look at your loop again. You have
for jj=1:floor(Ls/2)
if store(jj*2)-store(jj*2-1)==0
store([store(1,:)==store(1,jj*2)])=[];
store([store(1,:)==store(1,jj*2-1)])=[];
end
end
Upon the first match, you delete some elements of "store", so it becomes smaller. It no longer has the same length. When jj reaches 1 beyond the new length, you have a problem.
Furthermore, suppose that when jj=1, you delete element 2. Then element 3 "falls down" into where element 2 used to be. Then you go on to jj=2 and so test the new element 3 vs the new element 4. You have then missed testing what used to be element 3 and is now down in element 2.
I also suggest you think more about your test
store(jj*2)-store(jj*2-1)==0
which is equivalent to
store(jj*2)==store(jj*2-1)
Now when those two elements are equal, on the following line,
[store(1,:)==store(1,jj*2)]
is going to be the same as the
[store(1,:)==store(1,jj*2-1)]
on the line after that, because the two values are equal. But the first of the lines deleted all the elements with that value, so there are no more elements with that value left in the line after that. Your code is redundant. And that suggests there is a good chance you were not thinking properly about the relationship between the elements in the other lines of code.
2 commentaires
the cyclist
le 3 Fév 2013
The best thanks you can give Walter for a helpful answer is to "Accept" it, which may also help future users looking for similar answers.
Plus de réponses (1)
the cyclist
le 3 Fév 2013
Modifié(e) : the cyclist
le 3 Fév 2013
Probably the best way to debug this sort of problem is the following. Before running your code, type the command
>> dbstop if error
Then run your code. This will cause your code to halt execution when it reaches the error. You will be taken to the editor, in debug mode, where the error occurred. Then you can see exactly what is causing the error. Presumably some index into an array is getting larger than you expect.
After you are done, you can remove that by typing
>> dbclear if error
0 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!