how to over come vector mismatch error in plot

3 vues (au cours des 30 derniers jours)
Shwetha Padmanabha
Shwetha Padmanabha le 23 Oct 2019
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

Réponses (1)

Shubham Gupta
Shubham Gupta le 24 Oct 2019
Modifié(e) : Shubham Gupta le 24 Oct 2019
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)?
  1 commentaire
Shwetha Padmanabha
Shwetha Padmanabha le 27 Oct 2019
No, but thank you got the answer we just need to plot using different vector.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by