MATLAB: Very strange error of for loop

MATLAB

I made this kind structure code
but the result is not I had expecetd
k=1;
for i=1:1:100
if(i==1)
a=zeros(size(i));
b=zeros(size(i));
end
a(k)=sin(i);
b(k)=a(k)
k=k+1
end
a(k) display the sin wave
but b(k) dispay only one constant value
like y=3
what happend to my code?

Best Answer

You did not include the plot call you are using.
If you are plotting:
figure
plot(a,b)
it will show a straight line from (-1,-1) to (1,1) because both ‘a’ and ‘b’ have the same values.
.