# Check if number of changes from negative to positive on data table and perform set of conditional tests

1 view (last 30 days)
Sud Mudiyanselage on 1 Oct 2022
Edited: Sud Mudiyanselage on 17 Oct 2022
Conditional testing example 1 as follows:
18:41:40 -5.67 0.999
18:41:40 -5.66 0.994
18:41:40 -5.55 1.024
18:41:40 -5.38 1.049
18:41:40 -5.19 1.065
18:41:40 -4.42 1.175
18:41:40 -3.00 1.425
18:41:40 -1.81 1.393
18:41:40 0.68 1.342
18:41:40 0.23 2.333
18:41:41 0.44 2.166
if number of changes @ column 2 =1 , at the row # of change go 3 rows back of timestamp on column 1 and get the matching column 2 value. (answer should give -4.42)
Conditional testing example 2 as follows:
19:41:40 -5.67 0.999
19:41:40 -5.66 0.994
19:41:40 0.15 1.024
19:41:40 -5.38 1.049
19:41:40 -5.19 1.065
19:41:40 -4.42 1.175
19:41:40 -3.00 1.425
19:41:40 -1.81 1.393
19:41:40 0.68 1.342
19:41:40 0.23 2.333
19:41:41 0.44 2.166
If number of changes@ column 2 >1 and , then look at each change where gives highest value from column 3 and get the the corresponding timestamp in column 3 and go 3 rows back and get corresponding column 2 value. (answer should give -5.19)
Table doesn't have column headings .

dpb on 1 Oct 2022
Edited: dpb on 2 Oct 2022
A=[-5.67 0.999
-5.66 0.994
-5.55 1.024
-5.38 1.049
-5.19 1.065
-4.42 1.175
-3.00 1.425
-1.81 1.393
0.68 1.342
0.23 2.333
0.44 2.166];
% the engine
% case 1
N=1;
ix=find(diff(sign(A(:,1)))==2,N)+1;
A(ix-3,:)
ans = 1×2
-4.4200 1.1750
A=[-5.67 0.999
-5.66 0.994
0.15 1.024
-5.38 1.049
-5.19 1.065
-4.42 1.175
-3.00 1.425
-1.81 1.393
0.68 1.342
0.23 2.333
0.44 2.166];
% case 2
N=2;
ix=find(diff(sign(A(:,1)))==2,N)+1;
[mx,imx]=max(A(ix,3));
A(ix(imx)-3,:)
ans = 1×2
-4.4200 1.1750
NB: I believe either the first or the second answer is wrong; probably the second. -5.19 is four places preceding the location of the 2nd positive in the second case. The two results given are inconsistent with each other in the offset counting from the location of the positive value after the change...
Above will have to have error checking, etc., if the result of the find() is empty, etc., etc., ...
Sud Mudiyanselage on 17 Oct 2022
Edited: Sud Mudiyanselage on 17 Oct 2022
Yes i understand what your saying. I actually managed to fix the sign change from positive to negative. it is now working ....SO THANK YOU for your code helped me to get that last bit working .....thx heaps !!!
I do have another another issue for a different data set, hopefully you can give some guidance. i have a set of data attached (.txt file) represents heights vs time.
I need to check within the whole profile, how many times the 25, 70 and 99 meter height peak occurs ( i am not after # of occurences). Answers should be as follows as shown in the image:
I have tried using following methods but neither had luck, maybe i need to do some looping to check .... i am not sure. thanks in advance.
[pks_25,locs_25]=findpeaks(data,'MinPeakheight',25);
Num_peaks_25=(findpeaks(data,'MinPeakheight',25,'MinPeakDistance',n));
sum(islocalmax(data,'FlatSelection','First'));

### Categories

Find more on Sources in Help Center and File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!