Check if Column has Correct Sequence of Numbers
조회 수: 8 (최근 30일)
이전 댓글 표시
I have a column of motion tracking data where there are supposed to only be 3 values (integers) and they should repeat in the same order every 3 rows.
For example, the order is 52630, 1, 2. It repeats ilike that for a few thousand lines.
Once or twice in the column, it will skip one of these values. I need to be able to detect when this happens, and if possible remove the rows from the table where it happens.
For example, if there is a 1 missing in the sequence, I need to be able to delete the rows that containt the 52630 and 2 that are missing the 1 in between them.
I've tried a few different things but none seemed to work as I expected them to.
Thanks!
댓글 수: 0
채택된 답변
KALYAN ACHARJYA
2021년 2월 25일
편집: KALYAN ACHARJYA
2021년 2월 25일
Steps:
1.Create the complete Table with original data (including missing data)
3. Get the rows from the logical matrix of the result of step 2
[r,~]=find(result3==1);
4. Remove all those rows from the table
table_varible_name(r,:)=[]
댓글 수: 3
KALYAN ACHARJYA
2021년 2월 25일
편집: KALYAN ACHARJYA
2021년 2월 25일
As per the given attached data here an example
data=repmat([52630 1 2],[1,5]);
data(8)=[]; % Creation of sample data
T=table(data')
T =
14×1 table
Var1
_____
52630
1
2
52630
1
2
52630
2
52630
1
2
52630
1
2
First Option: (Hard Coding)
result=diff(T.Var1)
Here you have to make a comparison in the result data or use ~"find" function to those undesired results, as you have known patterns, you know the diff results of consecutive numbers.
result =
-52629
1
52628
-52629
1
52628
-52628
52628
-52629
1
52628
-52629
1
See index 7 number -52628 is not matched with pattern diff results.
Second Option
idx = findpattern(T.Var1,[52630 1 2])
idx =
1 4 9 12
idx_final=sort([idx,idx+1,idx+2]); % This you can generelize;
% it gives the 1st index of the pattern matched, three number in the pattern
% Hence I have added extra 2 to get the indices
% Total addition required length(pattern_array)-1
idx_final =
1 2 3 4 5 6 9 10 11 12 13 14
Now find the indices which are not present the the idx_final indices
>> find(ismember(1:length(T.Var1),idx_final)==0)
%.....................^ Rows number in the table
ans =
7 8
Third Option: normxcorr(): I have not tested with the sample given data
Fourth Way: There are multiple ways, choose as per your requirements and understanding
Once you get the rows deletion is easy
table_variable(idx,:)=[]
Hope it Helps :)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!