
For loop mistake?

igorman
I have been trying to run this code, but I believe there must be something wrong going on in the for loop part, and I would be grateful for anyone who can catch the mistake. I am not sure what I am missing.
I have two sets of data called rawwave3, rawwave5. Both have the same number of points and basically represent X, and Y values. I have a predetermined set of X-which I must compare with these two waves in the following manner. These predetermined X-values are in the wave called NextWave. The conditions are as follows,
For each Xvalue > the xvalue in NextWave, my code should must print out the Xvalues where Y value < 1. 1 is stored as a variable. The code I have is given below. My major difficulty is in using the index that comes out of the first step where we determine all the Xvalue > the xvalues in NextWave, and matching those indices with that of the Yvalue waves to basically print the Yvalues.
for(k=0; k<numpnts(NextWave); k+=1) print NextWave[k] for(j=0; j<numpnts(rawwave3; j+=1) //Goes through Xvalue wave if(rawwave3[j] > NextWave[k]) print rawwave3[j] //Compares each particular Xvalue with element of NextWave and if greater prints it out //It is here I need help. I need to find a way to match the index of the elements found satisfying the condition above. //Since rawwave3, and rawwave5 have the same number of elements, I can then take that matched index to do the step below. //I am stuck here. if(rawwave5[j] < crossing0) Yvalue = rawwave5[j] print Yvalue endif endif endfor endfor
for(j=0; j<numpnts(rawwave3; j+=1) //Goes through Xvalue wave
needs a right parenthesis fornumpnts(rawwave3
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
July 1, 2013 at 01:46 pm - Permalink
for ...
statement. Here is a condensed version. Otherwise, I am confused what you are trying to achieve.--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 1, 2013 at 01:51 pm - Permalink
for ...
statement. Here is a condensed version. Otherwise, I am confused what you are trying to achieve.Thank you for the help. I'm finding it difficult to exactly describe the purpose of my code. I can try explaining in detail once again. My data points are allotted in the following waves
XValues, YValues, Crossings0, Crossings1, ....
Xvalues are stored in rawwave3
Yvalues are stored in rawwave5
Crossings denotes files with the xvalue locations where each yvalue is crossed throughout the entire wave. The numbers at the end 0, 1, represent the index of the y-values in rawwave5, for identification sake.
Now the calculation I have to make is such that for each x in Crossings0, Crossings1...:
(1) for all x' > x, find the yvalues < 1, along with their corresponding xvalues
(2) for all x' > x, find the yvalues > 9, along with their corresponding xvalues
The values 1 and 9 are just set constants, so I denoted them under variables crosssing0, and crossing1.
I fixed the code like you said, for (1) , but am just having trouble being efficient in processing the data with it:
July 1, 2013 at 03:11 pm - Permalink
Can you illustrate what you want in a better way? Perhaps you could make a graphical representation of the data and lines+marks that show what you want. Or give a set of arrays with numerical values.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 1, 2013 at 07:10 pm - Permalink
As written in your example, the size of the output waves will not change while the for loops are running. I don't think this is the behavior you desire.
The code, as revised in this note, will add a new row each time a crossing is found, this will result in one extra row when execution is finished, but will solve the problem of overwriting the previous result. You should be able to avoid the extra row with a bit more thought.
By the way, I think I see what you are trying to do with the crossings, but the purpose of nextwave is not clear. Maybe you can add an explanation of that.
July 2, 2013 at 05:21 am - Permalink
Hi JJ, I'm sorry for the hassle, but here you go, I have attached a picture that shows you the arrays that I'm working with.
Basically,
-NumLevelCrossing indicates the number of times the particular y value is crosssed in the entire wave, described by the XValues, and YValues.
-You can ignore Column 5 All Crossings.
-Crossings0, Crossings1... Crossings 6 and so on and so forth, basically describe the locations of each crossing for each particular Yvalue. So Crossing0 describes, the '3' Crossings at Xvalue location in terms of their points: 0, 10, and 29.
(I used FindLevels to find these locations, if I want them in terms of the XValues (column 2) instead of points, should I add /P ? )
-My calculation involves two parts:
For each x-value seen in each Crossings0, Crossings1 ... Crossings 6 file, I have to calculate such that
(1) for all x' > x, find the y-values (from YValues) < 1, and note them down along with corresponding x-values (from XValues).
(x' is just a parameter to denote any other x value > the particular x value chosen,
so if i say x = 0, then all x values above it , in my particular sample will have to be considered)
(2) for all x' > x, find the yvalues > 9, along with their corresponding xvalues
The values 1 and 9 are just set constants, so I denoted them under variables crosssing0, and crossing1, in my code.
This is my full code so far. The commented section is something that I tried to see if it works:
July 3, 2013 at 05:41 pm - Permalink