Check if number of changes from negative to positive on data table and perform set of conditional tests
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sud Mudiyanselage
am 1 Okt. 2022
Bearbeitet: Sud Mudiyanselage
am 17 Okt. 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 .
please help, Thank you !!!
0 Kommentare
Akzeptierte Antwort
dpb
am 1 Okt. 2022
Bearbeitet: dpb
am 2 Okt. 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 Kommentare
dpb
am 8 Okt. 2022
Bearbeitet: dpb
am 8 Okt. 2022
But the problem is the conditions themselves aren't unique so a data set that satisfies one also satisfies another -- who wins? Unless some other criterion is added to differentiate those, whichever is first in the test sequence will be the winner. Left in that condition (so to speak :) ), then there's no point in having the other condition; it'll never be satisfied so might as well not be there at all.
You've got the ideas of how to make such tests for the condition of sign changes; you've just got to decide what it is that you actually want the results to be and structure the code/refine the condition definitions to provide those results, but at this point you've not defined what is the actual result to be returned in the multiple sign changes case vis a vis just one for at least one conundrum to be resolved.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!