matrix dimension must agree

4 Ansichten (letzte 30 Tage)
Carlos Antonio Hernández Guerrero
Beantwortet: Shubham Gupta am 27 Sep. 2019
I have this code and i wanna plot the fourier serie of my signal in frecuency, I've been traying to plot it but in the line 25 i have an error "matrix dimension mut agree" and i can't fix it. could someone help me with this ?
%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
Fs=5*t;
Ts=1./Fs;
L=1500;
tl=(0:L-1).*Ts;
y4=fft(f1);
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')
  2 Kommentare
Shubham Gupta
Shubham Gupta am 23 Sep. 2019
In line,
tl=(0:L-1).*Ts;
Ts is of dimension 1x199 and you are muliplying it with a vector of dimesion 1x1500.
Since, you are doing element wise multiplication, size of arrays being multiplied should be equal.
One way to solve this is to modify 'L' to match the size of 'Ts' for element-wise multiplication
I hope this helps !
Carlos Antonio Hernández Guerrero
you`re amaizing, thanks

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Shubham Gupta
Shubham Gupta am 27 Sep. 2019
In line,
tl=(0:L-1).*Ts;
Ts is of dimension 1x199 and you are muliplying it with a vector of dimesion 1x1500.
Since, you are doing element wise multiplication, size of arrays being multiplied should be equal.
One way to solve this is to modify 'L' to match the size of 'Ts' for element-wise multiplication
I hope this helps !

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by