Index Exceeds matrix dimensions error message in my Speech Segmentation code, would you help, please?

2 次查看(过去 30 天)
Hi, I am trying to segment a signal into its non-zero blocks. Below is the algorithm that I wrote to find the number of non-zero elements in each non-zero block of the signal. the vector Num is supposed to output these numbers. I get the error message: ??? Index exceeds matrix dimensions.
Error in ==> SegmentSignal at 56 if Numcount(j-1,1)==Numtimes
Please Help!
Thank you.
flags =(NormEnergySigX>0.05);
if flags(1)==0
k=0;
Num=[];
Numtimes=0;
Numcount=[];
for j=1:length(flags)
if (flags(Numtimes+1)==0)
Numtimes=0;
end
if flags(j)==0
Numtimes=Numtimes+1;
Numcount(j,1)=(flags(j)==0)*Numtimes;
end
if flags(j)==1
if Numcount(j-1,1)==Numtimes
k=k+1;
Num((Numcount(j-1,1)==Numtimes),k)=Numtimes;
if flags(Numtimes+1)==1
times=0;
if flags(j)==1
Numtimes=Numtimes+1;
Numcount(j,1)=(flags(j)==1)*Numtimes;
if Numcount(j-1,1)==Numtimes
Num((Numcount(j-1,1)==Numtimes),k)=Numtimes; % Num is supposed to contain the number of non-zero elements
% in each consecutive chunks of non-zero elements in flags.
end
end
end
end
end
end
end

采纳的回答

Walter Roberson
Walter Roberson 2012-10-22
You do not create Numcount(j,1) unless flags(j) is 0, or unless flags(j) is 1 and a series of additional conditions all apply. If you were to encounter two locations in a row where the combination of those situations did not apply, then when you went to test Numcount(j-1,1) then that would not have been created yet so you would get the index out of range method.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulation, Tuning, and Visualization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by