You compute all elements of V and H, so they are fully defined at the moment you want to select relevant times. You can use logical indexing based on the output of relational operators (involving V, H, and threshold values), and avoid this iterative process that you are trying to implement with the nested WHILE loop.
Here is an example that you can then apply/adapt to your case: assume that you have t, x, and y, and you want to identify y that are associated with t>4 and x>=1.
>> t = 1 : 10
t =
1 2 3 4 5 6 7 8 9 10
>> x = (t-5).^2
x =
16 9 4 1 0 1 4 9 16 25
>> y = 101:110
y =
101 102 103 104 105 106 107 108 109 110
Now we can build a vector of logicals whose elements are 1 (true) where both conditions (on t and x) are true, as follows:
>> id = t > 4 & x >= 1
id =
0 0 0 0 0 1 1 1 1 1
>> class(id)
ans =
logical
If you look where 1's are, you can see that it corresponds to places where t>4 and x>=1 simultaneously.
Now this vector of logicals, id, can be used to index any array along a dimension with same length as id. In particular, we can use it to indexselect elements of y:
>> y(id)
ans =
106 107 108 109 110
If you check, these are the relevant values of y (that correspond to elements of t and x which verify both conditions).
As you can see, there is no loop here; we did it in a "vector" way. We also avoided using FIND. If you look at what you are doing when you use FIND, you will realize that you would have done something like:
>> pos = find(t > 4 & x >= 1)
pos =
6 7 8 9 10
>> y(pos)
ans =
106 107 108 109 110
but you can see that the argument of FIND is indeed the vector of logicals that we named id above (FIND returns in fact just the position of the non-zero/false elements of its argument). You can then use these positions to index y (this is called subscript or linear indexing), but you get the same elements using directly the vector of logicals (called logical indexing), so there is no point in making the extra step of using FIND.