When I run the file I get an error

1 visualización (últimos 30 días)
Hernan Reyes
Hernan Reyes el 29 de Sept. de 2020
Respondida: Ameer Hamza el 29 de Sept. de 2020
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)');

Respuestas (2)

Xingwang Yong
Xingwang Yong el 29 de Sept. de 2020
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 el 29 de Sept. de 2020
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)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by