[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I replace this "for" loop?
From: |
Keith Goodman |
Subject: |
Re: How do I replace this "for" loop? |
Date: |
Tue, 31 May 2005 14:26:16 -0700 |
The two methods I suggested don't always give the same output.
If x is 3.14, which is greater than 3, it becomes 3.14-2pi, which is
less than -3, so, in your example, it should be set back to 3.14. The
second example I gave obviously doesn't do that.
On 5/31/05, Keith Goodman <address@hidden> wrote:
> On 5/31/05, Robert A. Macy <address@hidden> wrote:
> > How do I replace these "for" loops?
> >
> > for i=1:rowsdata
> > for k=1:columnsdata
> > angleofdata(i,k)=angle(data(i,k));
> > if (angleofdata(i,k)>3)
> > angleofdata(i,k)=angleofdata(i,k)-2*pi();
> > endif
> > if (angleofdata(i,k)<-3)
> > angleofdata(i,k)=angleofdata(i,k)+28pi();
> > endif
> > endfor
> > endfor
>
> Here's one way:
>
> x = angle(data);
> x(x > 3) = x(x>3) - 2*pi;
> x(x < -3) = x(x < -3) + 2*pi;
>
> Another:
>
> x = angle(data);
> x = x - (x > 3)*2*pi + (x < -3)*2*pi;
>
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------