Index exceeds matrix dimensions.

1 visualización (últimos 30 días)
Boris Novosad
Boris Novosad el 5 de Abr. de 2020
Comentada: Boris Novosad el 5 de Abr. de 2020
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
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?
Boris Novosad
Boris Novosad el 5 de Abr. de 2020
Hello geoff, yes, nastdelka = 886. I solved the problem by running the code without the Fvz, that means I don´t have to multiply nastdelka with Fvz. But I didn't understand why did the error appeared.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
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
Boris Novosad
Boris Novosad el 5 de Abr. de 2020
Thanks Image Analyst, now I see why I can't run the loop properly.
Skipping n = 17689 because 17720 (which is n+1+2*WL) is longer than data, which has only 886 elements in it.

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by