how to over come vector mismatch error in plot
3 次查看(过去 30 天)
显示 更早的评论
tp=2.2676*10^-3;
Ts=22.6757*10^-6;
n=0:Ts:100;
fp=(1/tp);
w=2*pi*fp;
p=sin(w*n*Ts);
p(find(p<0))=0;
data = randi([0,1],1,100);
a=[];
for k=1:2:100
if data(k)==0 && data(k+1)==0
a=[a 1];
elseif data(k)==0 && data(k+1)==1
a=[a i];
elseif data(k)==1 && data(k+1)==0
a=[a -1];
elseif data(k)==1 && data(k+1)==1
a=[a -i];
end
end
y_s=conv(a,p);
plot(n,y_s);
vector mismatch between n and y_s
0 个评论
回答(1 个)
Shubham Gupta
2019-10-24
编辑:Shubham Gupta
2019-10-24
You can try :
tp=2.2676*10^-3;
Ts=22.6757*10^-6;
n=0:Ts:100;
fp=(1/tp);
w=2*pi*fp;
p=sin(w*n*Ts);
p(find(p<0))=0;
data = randi([0,1],1,100);
a=[];
for k=1:2:100
if data(k)==0 && data(k+1)==0
a=[a 1];
elseif data(k)==0 && data(k+1)==1
a=[a i];
elseif data(k)==1 && data(k+1)==0
a=[a -1];
elseif data(k)==1 && data(k+1)==1
a=[a -i];
end
end
y_s=conv(p,a,'same');
plot(n,y_s);
I hope this is what you want, let me know if you have doubts !
Side Note : Did you really mean to add 'i' (imaginary number) to the 'a' vector or you meant to add 'k' (for loop's variable)?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!