When I run the file I get an error

조회 수: 1 (최근 30일)
Hernan Reyes
Hernan Reyes 2020년 9월 29일
답변: Ameer Hamza 2020년 9월 29일
Hello when I run the following code, I get an error of
Error using plot
Vectors must be the same length.
Error in convolution (line 8) plot (t, f_pulse);
Can you help me please Thank you
t=-pi:0.01:pi;
f_pulso=[zeros(1,1000*3.14+1),ones(1,1000*3.14+1),zeros(1,1000*3.14+1)];
a=2*pi;
b=cos(a*50*t);
f_conv=conv(f,f_pulso);
figure(1);
subplot(3,1,1);
plot(t,f_pulso);
title('Señal Pulso');
xlabel('Tiempo(t)');ylabel('e(t)');
subplot(3,1,2);
plot(t,b);
title('cos(2.pi.t)');
xlabel('Tiempo(t)');ylabel('cos(2*pi*100*t)');
%Convolucion
f_conv=conv(f,f_pulso);
subplot(3,1,3);
plot(t,f_conv(l:length(f)),'r')
title('Convolucion');
xlabel('Tiempo(t)');

답변 (2개)

Xingwang Yong
Xingwang Yong 2020년 9월 29일
You should provide a reproducible snippet. I copy your code and run, it turns out "Unrecognized function or variable 'f'." at line 5.
By the way, you can use "Insert a line of code" tool in the toolbar for better readability.

Ameer Hamza
Ameer Hamza 2020년 9월 29일
As the error message indicates, the x and y vectors must have equal lengths. For example,
f_pulso=[zeros(1,1000*3.14+1),ones(1,1000*3.14+1),zeros(1,1000*3.14+1)];
t=linspace(pi, pi, numel(f_pulso)); % instead of t=-pi:0.01:pi;
plot(t, f_pulse)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by