Setting Up an If loop in a For loop Problem
igorman
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.
or
My code is as follows but am not sure what is going wrong. I would appreciate any comments:
January 7, 2014 at 01:41 pm - Permalink
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
&lt;
and for > use&gt;
January 7, 2014 at 02:17 pm - Permalink
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:
// 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
January 7, 2014 at 03:11 pm - Permalink
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.
January 8, 2014 at 01:09 am - Permalink