read a file .txt with 'm' rows and 5 columns and ....
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Jarrod Rivituso
on 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,:)
More Answers (0)
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!