I have the following array, but I would like to do with a matrix but to start, It will be enough to see the results.
I can not put a shorter array because I need to check before in long ones.
First of all, I fix two values, a = min value, b = max value After that, I fix c as the number of consecutive values I want to consider.
So, taking into account above, I would have to loop through the array or whatever, to save a new array , which has the start from the c consecutive values between these two max and min restrictions.
To put an example, I have the following: a = 25 max value b = 15 min value c = 4 number of elements which satisfy conditions , that should be consecutive
321321 233321 546121 321516 321215 23123 23164 35465 31265 2155 2121 215 120 100 90 50 30 25 ->satisfies 20 ->satisfies 18 ->satisfies 15 ->satisfies 14 12 16 10 4 8 9
and the output should be the following:
25 20 18 15 14 12 16 10 4 8 9
and I would save a new array with this ouput. It should not take care if there is a value higher than the previous one, being the main condition, that have to be consecutives.
In the file, there is some NaN rows, so, It would be good if the solution skips this values. If anyone could give me the solution with the file I uploaded would be more than valuable. Because I need to test it in real data.
I hope to have been enough clear in my explanation.
Any help is welcome.
No products are associated with this question.
x = dlmread('path_to_cte.txt'); z = x(~isnan(x)); t = z >= 25 & z <= 15; n = cumsum([false;diff(t) == 1]); out = z(n(end) == n);
or with use strfind
a = 25; b = 15; c = 4;
p = [false;z >= b & z <= a;false]; t = p(:)'; ii = [strfind(t,[0 1]);strfind(t,[1 0])-1]; out = z(ii(1,diff(ii)+1 >= c):end);