Index exceeds matrix dimensions.

2 ビュー (過去 30 日間)
Boris Novosad
Boris Novosad 2020 年 4 月 5 日
コメント済み: Boris Novosad 2020 年 4 月 5 日
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 件のコメント
Geoff Hayes
Geoff Hayes 2020 年 4 月 5 日
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 2020 年 4 月 5 日
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.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 5 日
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 件のコメント
Boris Novosad
Boris Novosad 2020 年 4 月 5 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by