read a file .txt with 'm' rows and 5 columns and ....
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I must open a .txt file and to manipulate the rows to delete the rows that not corresponding to some arguments. The file is like this:
18,2554 0 0 138 9,365
18,0262 104 0 0 10,562
19,3685 0 0 108 11,011
19,4065 108 206 0 11,451
So, after read the program must to compare the 2nd, 3rd and 4th columns to know if they have values =< 108 (integer) and at the same time zeroes in the other two columns. According to the example above, the rows 2 and 3 must be deleted. Any help???? Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Jarrod Rivituso
am 30 Apr. 2011
Ok i was curious...
data = dlmread('myFile.txt','\t') %assuming tab delimited
colsOfInterest = data(:,2:4)
numOfZeros = sum((colsOfInterest == 0),2)
totalRowSum = sum(colsOfInterest,2)
rows2keep = (totalRowSum <= 108) & (numOfZeros == 2)
newData = data(rows2keep,:)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!