Check if number of changes from negative to positive on data table and perform set of conditional tests
1 view (last 30 days)
Show older comments
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 .
please help, Thank you !!!
0 Comments
Accepted Answer
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,:)
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,:)
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., ...
8 Comments
More Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!