[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I replace this "for" loop?
From: |
Tom Holroyd |
Subject: |
Re: How do I replace this "for" loop? |
Date: |
Tue, 31 May 2005 17:21:30 -0400 |
User-agent: |
Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324) |
Robert A. Macy wrote:
How do I replace these "for" loops?
for i=1:rowsdata
for k=1:columnsdata
angleofdata(i,k)=angle(data(i,k));
octave:1> help angle
angle is a built-in mapper function
-- Mapping Function: angle (Z)
See arg.
"Mapping" means you can pass the whole matrix to it.
angleofdata = angle(data);
if (angleofdata(i,k)>3)
angleofdata(i,k)=angleofdata(i,k)-2*pi();
endif
Tests are similar.
idx = find(angleofdata > 3);
gives you indices of elements that satisfy the condition, so
angleofdata(idx) = angleofdata(idx) - 2 * pi;
--
Dr. Tom Holroyd
"A man of genius makes no mistakes. His errors are volitional and
are the portals of discovery." -- James Joyce
-------------------------------------------------------------
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
-------------------------------------------------------------