When I run the file I get an error
1 次查看(过去 30 天)
显示 更早的评论
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)');
0 个评论
回答(2 个)
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.
0 个评论
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!