- The description is inconsistent; none are extant in the sample dataset with >2 repeats so used 2 as the lower count
- Used only 5&6 as the grouping variables even though one place says "5,6 & 8*' because
- "MARKUS" and "MAKRUS" don't match in original dataset; not clear if this is just a typo or supposed to be real. If just a typo, if corrected, then 5,6,&8 would also produce two sets in the result.
How to exctract specific elements from .txt file?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have one .txt file with 10 columns. In columns 5,6 & the same elements are included.
Considering that, I would like to extract from this input all the rows that include same elements in columns 5,6 & 8 that might be repeated more than 2 times in the table array.
I tried unique and ismember commands, but I cannot syntax the suitable command.
For example:
Input :
4 65 7.5 MGK 4 5 66 MARKUS 46.63641 65
11 26 5 LEON 78 93 88 LUTHER 50.3554 5
6 2 6.5 NDSGN 4 5 77 MAKRUS 59.67196 3
6 8 4.5 ANGEL 24 23 99 JOHN 31.87303 -1
6 2 6.5 NDSGN 56 89 100 ALEX 100 0
9 6 4 MARY 56 89 100 ALEX 2 200
Output file:
4 65 7.5 MGK 4 5 66 MARKUS 46.63641 65
6 2 6.5 NDSGN 4 5 77 MAKRUS 59.67196 3
6 2 6.5 NDSGN 56 89 100 ALEX 100 0
9 6 4 MARY 56 89 100 ALEX 2 200
Could you please help me?
댓글 수: 0
답변 (1개)
dpb
2023년 4월 4일
d= [' 4; 65; 7.5; MGK ; 4; 5; 66; MARKUS; 46.63641; 65'
'11; 26; 5 ; LEON ; 78; 93; 88; LUTHER; 50.3554 ; 5'
' 6; 2; 6.5; NDSGN; 4; 5; 77; MAKRUS; 59.67196; 3'
' 6; 8; 4.5; ANGEL; 24; 23; 99; JOHN ; 31.87303; -1'
' 6; 2; 6.5; NDSGN; 56; 89; 100; ALEX; 100 ; 0'
' 9; 6; 4 ; MARY ; 56; 89; 100; ALEX; 2 ; 200'];
t=array2table(strtrim(split(string(d),';')));
t=convertvars(t,[1:3 5:7 9:10],'double')
[g,idx]=findgroups(t(:,[5 6]));
n=histc(g,unique(g));
[ia,ib]=ismember(g,find(n>1));
tU=t(find(ib),:)
NOTA BENE:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!