フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to fix: "Index exceeds matrix dimensions"?

2 ビュー (過去 30 日間)
Artur Pater
Artur Pater 2018 年 11 月 28 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I want to use fft on first cycle of sine wave to get all samples from it.
fs=1000;
t = 0:1/fs:0.2-1/fs;
x = 5*sin(2*pi*50*t);
plot(t,x)
To do it I used loop:
n = 20;
for i=n:length(x)
y = fft(x(i:i+n-1));
end
where n is number of samples/cycle (fs=1000, freq=50 Hz).
But MATLAB shows me an error "Index exceeds matrix dimensions" in line with y = fft(...).
How to fix it?

回答 (1 件)

Cris LaPierre
Cris LaPierre 2018 年 11 月 28 日
編集済み: Cris LaPierre 2018 年 11 月 28 日
It means you are indexing into x with a number that exceeds the size of x.
Checking the size of x, it is 1x200. Check the value of "i" when your code stops running. I get 182. Your index is
x(i:i+n-1)
or, when it errors out,
x(182:182+20-1)
x(185:201)
x(201) does not exist. Hence the error message.
the fix is to adjust your indexing so you doen't exceed 200.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by