How to select rows with a particular value form one text file and write desired rows in new file?
3 ビュー (過去 30 日間)
古いコメントを表示
Marisabel Gonzalez
2018 年 11 月 29 日
編集済み: KALYAN ACHARJYA
2018 年 11 月 29 日
Let's say I have the following data
3 43.45 0.5
4 23.21 0.4
5 32.84 0.3
6 67.02 0.4
2 13.00 0.2
3 23.32 0.1
How would I only select the rows in which the 3rd column elements are less than 0.4 and write them into a new file?
Then in this new file I would only have row 3,5 and 6 in this new file.
0 件のコメント
採用された回答
KALYAN ACHARJYA
2018 年 11 月 29 日
編集済み: KALYAN ACHARJYA
2018 年 11 月 29 日
k=load('test1.txt');
idx=k(:,3)<0.4;
k(idx,:)
%Next save the file as new name, hope you can do that.
%Still if you need help, comment below
ans =
5.0000 32.8400 0.3000
2.0000 13.0000 0.2000
3.0000 23.3200 0.1000
0 件のコメント
その他の回答 (1 件)
Bob Thompson
2018 年 11 月 29 日
編集済み: Bob Thompson
2018 年 11 月 29 日
I'm assuming the file only has numeric data.
data = dlmread('yourfilename.txt');
datan = data(data(:,3)<0.4,:);
dlmwrite('yournewfilename.txt',datan,'delimiter',' ');
You can change precision, by adding 'precision' and some form of precision (similar to fprintf), to the dlmwrite command. This will allow you to have extra zeroes, or spaces or things of that nature.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!