Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Curious
Posts:
2,139
Registered:
12/6/04


Re: Help with a for if loop
Posted:
Nov 6, 2013 4:34 PM


"Terrell" wrote in message <l5e9h3$1tu$1@newscl01ah.mathworks.com>... > I am trying to make a for if loop work in matlab but am having no luck. It is as if the for loop runs once and then stops. The code is as follows: > > fs=4000; > Ts=1/fs; > N1=241; > tb=.055; > te=.115; > Ta=.060; > T=.050; > A=10; > fc=1000; > theta=0; > for t=1:.001:1; > if (T<=t) && (t>=0) > g2=A*cos(2*pi*fc*t+theta); > else > g2=0; > end > if (Ta<=t) && (t>=(T+Ta)) > g1=A*cos(2*pi*fc*(tTa)+theta); > else > g1=0; > end > end > > No matter what I do I end up with a 1 for t and 10 for g1 and g2. I can't seem to figure out how to get past this. Any help is appreciated,
I'm not sure what other result you are expecting. The loop is obiously running to completion since t = 1. On the last iteration of the loop: g2=A*cos(2*pi*fc*t+theta) g1=A*cos(2*pi*fc*(tTa)+theta) and since A=10, t = 1, and theta = 0 g1 = g2 = 10 because fc*(tTa) = 1000*(.94) = 940 and cos(2*pi*n) = 1 for any interger n.



