Index exceeds matrix dimensions.

조회 수: 8 (최근 30일)
Carlos Antonio Hernández Guerrero
I've been fixing this code, now i have a problem in line 29, that says "Index exceeds matrix dimensions." how can I fix it ?
%T=1/pi;
t=-pi:pi/99:pi;
A=2;
w0=(2.*pi)*(1./t);
f=A*sin(t)
f1=abs(f);
figure(1)
plot(t,f1)
%serie de fourier
%hold on
for n=1:2:40
y=f1+((2*A)/pi)*(sin(n*t)/n);
plot(t,y) ;pause(.2)
%hold off;
end
figure(2)
%fft
y2=f1+((2*A)/pi)*(sin(20*t)/20);
Fs=1500;
Ts=1./Fs;
L=1500;
tl=(0:L-1).*Ts;
y4=fft(y2);
P2=abs(y4./L);
P1=P2(1:L./2+1);
P1(2:end-1)=2*P1(2:end-1)
g= Fs*(0:(L/2))/L;
plot(handles.axes2,g,P1,'r')

채택된 답변

Shubham Gupta
Shubham Gupta 2019년 9월 23일
P2 is an array of dimesion 1x199 and L=1500. So, when you write :
P1=P2(1:L./2+1);
that means
P1 = P2(1:751);
So, indeces of P2 greater than 199 exceeds than it's maximum size of 199.
One way to correct this, will be to modify 'L' .
I hope it helps !
  댓글 수: 1
Carlos Antonio Hernández Guerrero
you're rigth, thank you so much, i already realized that it was something about the dimension but i can´t see where i had to modify, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by