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 Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by