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

조회 수: 1 (최근 30일)
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 !!!

채택된 답변

dpb
dpb 2022년 10월 1일
편집: dpb 2022년 10월 2일
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., ...
  댓글 수: 8
dpb
dpb 2022년 10월 8일
편집: dpb 2022년 10월 8일
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.
Sud Mudiyanselage
Sud Mudiyanselage 2022년 10월 17일
편집: Sud Mudiyanselage 2022년 10월 17일
hi dpb ... Thanks for your reply.
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:
1. 25 meter height loading - 4 times (red color)
2. 70 meter height loading - 2 times (green color)
3. 99 meter height loading - 1 time ( pink color)
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'));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by