read a file .txt with 'm' rows and 5 columns and ....
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jarrod Rivituso
2011-4-30
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,:)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!