[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Avoiding looping when applying a 'find' function to an array

From: Harbinson, Jeremy
Subject: Avoiding looping when applying a 'find' function to an array
Date: Wed, 13 Apr 2005 16:48:52 +0200

I have a problem which can be easily solved by looping, but which I
would like to try to solve by avoiding loops.
I need to transform one array to another equally sized array using a
look-up table. 

If the input array is A, then I take the value of each element of array
A one by one, and using the 'find' function, I find the appropriate
value for the matching element for the output array via the look-up
table. Looping over every element in array A works just fine - for each
element in A I can obtain an output value for the output array. However
I can not think of way of doing this same task without looping - that
is, applying the 'find' function to each element and producing an output
array without looping. 

If I input:

Location_of_value_for_output_array = find(input_array(1,1) ==

then I get the correct location in the look-up table for the value
required in the output array, and then I increment the index of
input_array etc - this is slow because the array is 512 times 512 array
(a graphics file) and the look-up table is 574 rows long. 

However if I try the following:

Location_of_value_for_output_array = find(input_array(:,:) ==


Location_of_value_for_output_array = find(input_array == look_up_table)

then I have no success.
Any help would be much appreciated,
Jeremy Harbinson      

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]