how to over come vector mismatch error in plot
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Shubham Gupta
il 24 Ott 2019
Modificato: Shubham Gupta
il 24 Ott 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)?
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!