i am trying to extract the values from filterData vector. I want to pull out the values and the index they are located at but i am stuck at what to actually put inside the if statement. if there is a better way i am open to trying that too. but basically im trying to find the peaks of my vector. then i want to find the distance between each peak in terms of number of indexes.
thanks
1 2 3 4 5 6 7 8 9 10 11
M = 0.75 * max;
for (i=0; i<countlines; i++)
{
if(filterData[i-1] < filterData[i] && filterData[i+1] < filterData[i] && filterData[i] > M)
{
cout << i << " : " <<filterData[i] <<endl;
}
}
You don't know how many peaks there will be, so you can record their indices in a vector<int>; you can push_back( i ) into that collection every time that you identify a peak.
Your method as given will, however, crack up in several circumstances:
- your peak may occur at one or other end, so you won't always be able to test both neighbours;
- you will have to decide what to do with a "plateau" (several values the same).
You haven't given enough code to show how to implement a vector and push_back().
Please also take into account the comments I made about identifying peaks. At present, your method may fail to identify quite a few, independent of storing them