Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Help with a for if loop
Replies: 6   Last Post: Nov 7, 2013 8:48 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 1,982
Registered: 12/6/04
Re: Help with a for if loop
Posted: Nov 6, 2013 4:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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*(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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.