- 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?
1 次查看(过去 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!