vectors

Guys, i have two codes that fill up vectors and then afterwards another piece of code should use the numbers in vector for further processing. When I use 1st code data is processed and I get expected results, but when I am trying to use 2nd code, subsequent function returns the same number as it gets without processing. I guess that it might be related to the way I save data into vector, but I have no idea how to fix it. Any help will be greatly appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
1st code:
  for(int i = 0; i < new_n; i++)
	{
        Deriv[i] = Deriv[i] / m_max_1;
		if(Deriv[i] < 0.100)
			Deriv[i] = 0;
		if(i < 8)
			continue;
		else
		if(Deriv[i - 1] > Deriv[i] && Deriv[i - 1] > Deriv[i - 2])
		if(!peaks.empty()) //checking whether this is peak or not
		{
		    bool moreThenZero = true;
		    bool Zero = false;
		    for(int j = peak_pos.back(); j < (i - 1); j++)
		    {
			if(Deriv[j] == 0)
			{
			   Zero = true;
			   break;
			}
			}
			if(Zero)
			{
			peaks.push_back(Deriv[i - 1]);
			peak_pos.push_back(i - 1);
			peak_posD.push_back(new_arr[i - 1][0]);
			}
				}
				else
			if(peaks.empty())
			{
			peaks.push_back(Deriv[i - 1]);
			peak_pos.push_back(i - 1);
			peak_posD.push_back(new_arr[i - 1][0]);
			}
    }

2nd code:
for(int i = m_max_2; i < new_n; i++)
	{
        Deriv[i] = Deriv[i] / m_max_1;
		if(Deriv[i] < 0.100)
			Deriv[i] = 0;
		if(i < 8)
			continue;
		else
			{
			for(int j = i; Deriv[j] > 0; j++)
			{
  if(Deriv[j] > Deriv[m_max_2] && Deriv[j] > Deriv[j + 1] && Deriv[j] > Deriv[j - 1])
			{
			m_max_2 = j;
			}
			}
			}
			if(Deriv[i] == 0 && Deriv[m_max_2] > 0)
			{
				peaks.push_back(Deriv[m_max_2]);
				peak_pos.push_back(m_max_2);
				peak_posD.push_back(new_arr[m_max_2][0]);
				Deriv[m_max_2] = 0;
			}
    }
We're missing a whole lot of context.

When posting code, please make sure it is a minimal but compilable snippet of code that (still) reproduces your problem. Preferably with a better description of the problem than "some other code doesn't work when I use this."
Here is the code that i use to process the dara from peak_pos vector:
int UnknownGe::set_up_lim(int k)
{
int j = peak_pos[k - 1];
while(Deriv[j] > 0)
{
j--;
if(Deriv[j] == 0 || new_arr[j][0] < 2)
break;
}
if(new_arr[j][0] < 2 && Deriv[j] > 0)
return (j + 1);
if(k == 1)
{
if(new_arr[j][0] - new_arr[0][0] < 10)
return j;
else
return (j - 2);
}
else
if(peak_posD[k - 1] - peak_posD[k - 2] < 10)
return j;
else
return (j - 2);
}

and this function is supposed to find a point, in Deriv[j] array, which contains 0, and when it gets value from the 2nd code, it returns the same value as it gets, while using the 1st code it returns expected value.
Topic archived. No new replies allowed.