"Terrell" wrote in message <firstname.lastname@example.org>... > 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*(t-Ta)+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*(t-Ta)+theta) and since A=10, t = 1, and theta = 0 g1 = g2 = 10 because fc*(t-Ta) = 1000*(.94) = 940 and cos(2*pi*n) = 1 for any interger n.