How to remove content from file
4 次查看(过去 30 天)
显示 更早的评论
In this text file there are two columns. In second column i want to remove all those rows which falls between 279 to 291. So, how to do it..?
0 个评论
回答(1 个)
Walter Roberson
2012-12-4
YourData = load('merged.txt');
YourData(YourData(:,2) > 279 & YourData(:,2) < 291, :) = [];
save('Newmerged.txt', 'YourData', '-ascii');
Note that I have interpreted "between" as meaning not equal to 279 or 291 exactly, the open interval (279,291), rather than the closed interval [279, 291]
2 个评论
Walter Roberson
2012-12-4
The above code removes all rows in which the second column is in (279,291), producing an output file which has two columns, with each row being one of the original rows.
If you just wanted to remove items from the second column leaving the first column entirely in place, then you would end up with a second column which was shorter than the first column, and MATLAB cannot store numeric arrays which do not have equal number of values in the columns.
I'm wondering if you are trying to exclude data in that range, or if what you want is only the data in that range?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!