Index exceeds matrix dimensions.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello people, I have this code and on the last row I am experiencing this error.
data - 886x1 double
time - 886x1 double
WL = 60; %nastaveni delky okna
kA = 7; %vahovaci konstanty
kF = 1;
mez = 2800; %nastaveni velikost meze
Fvz = 20;
nastdelka = length(data);
figure(2);
subplot(3,1,1);
plot(time,data); %zobrazeni vybraneho kanalu eeg signalu
xlabel('Čas [s]');
ylabel('Amplituda');
title('Pitch');
for n = 1:(nastdelka*Fvz-2*WL-1)
okno1=data(n:n+WL);
okno2=data(n+WL+1:n+1+2*WL);
Aw1(n) = sum(abs(okno1)); %vypocet amplitudy
Aw2(n) = sum(abs(okno2)); %jednotlivych oken
for m = 2:WL-1
Fw1(n) = sum(abs(okno1(m+1)-okno1(m-1))); %vypocet frekvence
Fw2(n) = sum(abs(okno2(m)-okno2(m-1))); %jednotlivych oken
end
G(n) = kA*abs(Aw1(n)-Aw2(n))+kF*abs(Fw1(n)-Fw2(n)); %mira rozdilu oken <-- ERROR OCCURANCE - Index exceeds matrix dimensions.
end
2 comentarios
Geoff Hayes
el 5 de Abr. de 2020
Boris - when I run your code (with dummy values assigned to the data and time arrays) I see the same error on this line
okno2=data(n+WL+1:n+1+2*WL);
Given that we are iterating as
for n = 1:(nastdelka*Fvz-2*WL-1)
and nastdelka is the length of data which is 886, does this make sense? Or are your arrays larger than 886x1?
Respuestas (1)
Image Analyst
el 5 de Abr. de 2020
Put this as the first lines inside your for loop
if n+1+2*WL > length(data)
fprintf('Skipping n = %d because %d (which is n+1+2*WL) is longer than data, which has only %d elements in it.\n'...
n, n+1+2*WL, length(data));
continue;
end
Now look in the command window after your loop finishes. What do you see?
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!