- 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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
dpb
el 4 de Abr. de 2023
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 comentarios
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!