From help-request at octave dot org Tue May 31 16:21:13 2005 Subject: Re: How do I replace this "for" loop? From: Keith Goodman To: "Robert A. Macy" Cc: help at octave dot org Date: Tue, 31 May 2005 14:19:46 -0700 On 5/31/05, Robert A. Macy wrote: > How do I replace these "for" loops? >=20 > for i=3D1:rowsdata > for k=3D1:columnsdata > angleofdata(i,k)=3Dangle(data(i,k)); > if (angleofdata(i,k)>3) > angleofdata(i,k)=3Dangleofdata(i,k)-2*pi(); > endif > if (angleofdata(i,k)<-3) > angleofdata(i,k)=3Dangleofdata(i,k)+28pi(); > endif > endfor > endfor Here's one way: x =3D angle(data); x(x > 3) =3D x(x>3) - 2*pi; x(x < -3) =3D x(x < -3) + 2*pi; Another: x =3D angle(data); x =3D 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 -------------------------------------------------------------