got a small question about grouping data points
changky
I have just recently started using Igor.
My first project requires me to calculate the difference between two consecutive points from a wave to calculate the time difference between the two points.
I have finished doing that.
Next I need to go through that data and pick out the time differences that are under a certain value . From those values, if two or more consecutive numbers are smaller than the given value, I would like to add them up.
I am having a little trouble on this last part.
Any suggestion ?
I would like to thank you guys in advance for all of your help
Cheers
I don't quite understand what you want to do, but let's say that you have a wave named wave1 which contains the difference between two consecutive points from your original wave. I've made such a wave using random data by executing the following command:
Now, create a copy of wave1.
Now, you want to look through wave2 for values below a certain value. For simplicity, I used 0 as that value. The first command below will look at all points in the wave except the first and last points in the wave, and set the point to the original value (that is, not to 0) if that point is < 0 and the point before or after it is also < 0. The next two lines do the same for the first point in the wave and the last point in the wave.
wave2[0] = (wave1[p] < 0) && (wave1[p+1] < 0) ? wave1[p] : 0
wave2[numpnts(wave1)-1] = (wave1[p] < 0) && (wave1[p-1] < 0) ? wave1[p] : 0
You might want to view these two waves in a table if you're confused by what this command did.
It's here where I don't understand what you want to do next. Do you want to get the sum of all time differences that are below a certain value and were below that value for two consecutive points? If that's the case then you can just do
But if you want the sum of each run of consecutive negative values, you'd need to loop through the wave a point at a time and store the sum of each run in a new wave.
By the way, there may be more efficient ways to do this than what I've shown above.
November 20, 2010 at 09:00 am - Permalink
your suggestion helped a lot!
now i can bypass doing loops and that makes things so much simpler!
With regard to the second part of my question instead of the simple sum of the entire wave, I only wanted to sum up the points in the newly created wave2 in blocks for example i have the following data set:
"2,3,4,2,1,0,0,0,3,4,5,7,0,0,0,1,0,2" I would like to sum up "2,3,4,2,1" & "3,4,5,7" & "1" & "2" separately meaning i would like to sum up 2+3+4+2+1 to create a new point and 3+4+5+7 as a separate point in a new wave.
I dont know if that is more clear than what i have posted before.
In any case, Thank you very very much for your help!
November 22, 2010 at 07:58 am - Permalink
Check this function if it does what you want:
wave ww
extract/indx/free ww,extracted,ww>0
extract/o extracted,extracted,extracted[p+1]-extracted[p]!=1
string newW=nameofwave(ww)+"_summedVals"
make/o/n=(numpnts(extracted)) $newW=sum(ww,p==0 ? 0 : extracted[p-1]+1,extracted[p])
end
It gives only correct results if the original wave is point scaled!
A
November 22, 2010 at 10:08 am - Permalink