Comparing rows between two 2D waves and extracting index on match

Hello, 

I have 2D waves. Wave1 is the superset and Wave2 is a subset of Wave1. Each row of the superset Wave1 has a code value assigned to it. Now, I need to pull out the code values that correspond to each row in Wave2. For this, I need to match the rows in Wave2 with their corresponding location in Wave1 and extract the index upon match. 

I am running 2 "for" loops that pick a row from Wave2, divide the whole row with each row in Wave1 and look for all cell values in the result to be 1. This is working but is really tedious and very painful on the eyes. 

I am curious if there is an in-built function in IGOR that permits direct row or column comparisons between two 2D waves and extracts the corresponding index when there is a match. 

Kindly let me know. 

Sincerely, 

Peeyush

When you say that Wave2 is a subset of Wave1, what does that imply about their corresponding dimensions?

If Wave2 has the same size, or can be padded to match Wave1, then MatrixOP "&&" operation should help you eliminate loops:

&&    Logical AND operator supports all real data types and results in a signed byte numeric token with the value of either 0 or 1. The operation acts on an element by element basis and is performed for each element of the operand waves.

 

Hi s.r.chinn, 

Wave2 has the same number of columns as Wave1 but a smaller number of rows. I just need to identify the row index in Wave1 that corresponds to each individual row in Wave2. Thanks for the tips about &&!

Sincerely,

Peeyush

In reply to by Peeyush Khare

Peeyush,

After further reflection, I believe another MatrixOP operation might be of more direct use to you:

correlate(w1,w2,opt)
    Returns the correlation of w1 with w2 subject to options opt. The dimensions of the result are determined by the largest dimensions of w1 and w2 with the number of rows padded (if necessary) so that they are even. Supported options include opt=0 for circular correlation and opt=4 for acausal correlation.

You would then have to identify the peak location of the maximum.

Do you care about efficiency? If not, you could simply use FindValue/RMD=[][0,0] in a wrapper function.

 

*Edited to provide example code:

function GetIndex(wave w, variable value)
    FindValue/RMD=[][0,0]/V=(value) w
    return v_value
end

duplicate/RMD=[][0,0] wave2 indices
indices = GetIndex(wave1, wave2)

let's say you want to set column 1 of wave2 to the value from column 1 of wave1 that matches the code value in column 0:

wave2[][1] = wave1[GetIndex(wave1, wave2[p][0])][1]