Setting Up an If loop in a For loop Problem

I have two tables set up.

Table 1 = [0, 1, 2, 3, 4, 5]

Table 2 = [554, 543, 554, 544, 564, 553]

All am trying to do is the following:

(1) I want to take the Value in Table 1, read it, and then identify it with the index of the same in Table 2. So for example Table1[0] = 0, and therefore we would find that Table2[Table1[0]] = 554

(2) From the given value of Table 1, I would then like to go through the entirety of Table 2, and append the value where the Data is first either lesser than A = 541, or greater than B = 553, and store the corresponding value accordingly in a
different table.

As I read Table1, I begin with Table1[0] = 0, I then proceed to make this 0 as my index for Table2 and proceed onwards to read the entirety of Table2, stopping and appending whenever the values in Table2 are < A or > B. For example,
starting with Table1[1] = 1, I would then proceed to read off all the values following Table2[1]: Table2[2] = 554, etc. In this case, the first value after Table2[1] is 554 which is > B so I append it to a different table and keep going, the next value Table2[3] = 544 which is neither >B or
My code is as follows but am not sure what is going wrong. Any comments would be appreciable.






I don't know why my post keeps getting cut, but here is the remaining part of the post:

or
My code is as follows but am not sure what is going wrong. I would appreciate any comments:
Your post is getting truncated because you are using angle brackets, which the forum software is interpreting as (invalid) HTML tags.

To post code, put it within <igor></igor> tags. To safely put an angle bracket in your post outside of code, use the corresponding HTML entity. For < use &amp;lt; and for > use &amp;gt;
I have two tables set up.

Table 1 = [0, 1, 2, 3, 4, 5]

Table 2 = [554, 543, 554, 544, 564, 553]

All am trying to do is the following:

(1) I want to take the Value in Table 1, read it, and then identify it with the index of the same in Table 2.

So for example Table1[0] = 0, and therefore we would find that Table2[Table1[0]] = 554

(2) From the given value of Table 1, I would then like to go through the entirety of Table 2, and append the value where the Data is first either lesser than A = 541, or greater than B = 553, and store the corresponding value accordingly in a different table.

As I read Table1, I begin with Table1[0] = 0, I then proceed to make this 0 as my index for Table2 and proceed onwards to read the entirety of Table2, stopping and appending whenever the values in Table2 are less than A or greater than B.

For example, starting with Table1[1] = 1. I would then proceed to read off all the values following Table2[1]: Table2[2] = 554, ... etc. In this case, the first value after Table2[1] is 554 which is greater than B so I append it it to a different table and keep going, the next value Table2[3] = 544 which is neither greater than B or less than A so I ignore and proceed etc.

My code is as follows but am not sure what is going wrong. Any comments would be appreciated:

Function Trial(Data1, Data2)
// Data1 = Table1, Data2 = Table2

Wave Data1
Wave Data2

Variable A = 541
Variable B = 553
Variable i, j, k
Variable XScale
Variable numPoints = numpnts(Data1) //Number of Points in the array
Variable numPoints2 = numpnts(Data2)

for(i=0; i<numPoints; i+=1)
   XScale = Data1[i]
   Wave TrialCrossingA, TrialCrossingB
   Make /N=(numPoints2)/O TrialCrossingA, TrialCrossingB
   //Makes new tables to append required values
   for(j=Xscale; j<numPoints2; j+=1)
            If(Data2[j] <= Xa)
                TrialCrossingA[i] = XScale
            Elseif(Data2[j] >= Xb)
                TrialCrossingB[i] = XScale
            Endif
   endfor
endfor

End

I don't understand your task fully, but I see some potential problems in your code. Maybe solving these will already fix the case.

1) You have a WAVE reference just before creating (overwriting) the very same waves. This is not wrong per se, but really not needed here, as MAKE already includes a WAVE reference. If that would not be the case you would have to do the wave reference rather after the make command.
2) Your variables Xa and Xb in the if-else statement are not defined. Maybe you wanted to write A, B instead?
3) You are saving the XScale value if the condition is met. From your description I rather get the feeling you wanted to do TrialCrossingA[i] = Data2[j]
4) You might run into a problem if numPoints is greater than numPoints2

Hope that helps.