how to over come vector mismatch error in plot

3 views (last 30 days)
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

Answers (1)

Shubham Gupta
Shubham Gupta on 24 Oct 2019
Edited: Shubham Gupta on 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 Comment
Shwetha Padmanabha
Shwetha Padmanabha on 27 Oct 2019
No, but thank you got the answer we just need to plot using different vector.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!