- #1
elecz
- 17
- 0
For loop in Matlab
I have written following code in MATLAB but the if condition inside the for loop isn't working properly. Can anyone tell what's the possible bug??
f=1000;
T=0.001;
g=0:0.00005:5;
w=2*f*T*pi;
s=sin(g*w);
plot(g,s);
grid on;
title('SINE FN');
xlabel(' x10^-3 TIME axis(ms)');
ylabel('sin(x)');
diary off
c=0;
for i=0:0.25:5
if(sin(w.*i)==0)
c=c+1;
end
end
display(c);
counter 'c' shows the value one instead of 11..
I have written following code in MATLAB but the if condition inside the for loop isn't working properly. Can anyone tell what's the possible bug??
f=1000;
T=0.001;
g=0:0.00005:5;
w=2*f*T*pi;
s=sin(g*w);
plot(g,s);
grid on;
title('SINE FN');
xlabel(' x10^-3 TIME axis(ms)');
ylabel('sin(x)');
diary off
c=0;
for i=0:0.25:5
if(sin(w.*i)==0)
c=c+1;
end
end
display(c);
counter 'c' shows the value one instead of 11..