how to over come vector mismatch error in plot
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Shwetha Padmanabha
el 23 de Oct. de 2019
Comentada: Shwetha Padmanabha
el 27 de Oct. de 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
0 comentarios
Respuestas (1)
Shubham Gupta
el 24 de Oct. de 2019
Editada: Shubham Gupta
el 24 de Oct. de 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)?
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!