Effective way to extract rows (range) from a text file
10 ビュー (過去 30 日間)
古いコメントを表示
I made a small loop to extract rows [range 183:262326] to make a column of 262144x1 column vector. The loop is very inefficient and takes a lot of time to execute. The code is below. Is there any more efficient way ? I dont want to use "Import Data" feature in MATLAB, I want to use code only.
fid=fopen('ABC.txt');
j=1;
for i=183:262326
linenum = i;
C(j,1) = textscan(fid,'%f',1,'delimiter','\n', 'headerlines',i-1);
j = j+1;
end
2 件のコメント
Image Analyst
2019 年 5 月 12 日
Maybe, but you forgot to attach abc.txt so we can't really help very effectively until you do. Maybe dlmread() or importdata() would do the trick, but we don't know until you attach the text file.
採用された回答
その他の回答 (1 件)
Jeremy Hughes
2019 年 5 月 12 日
Readling line by line is quite ineffecient.
Try this:
C = textscan(fid,'%f','delimiter','\n', 'headerlines',182);
2 件のコメント
Jeremy Hughes
2019 年 5 月 15 日
There must be something else in the file other than numbers that causes textscan to stop after the first number.
Glad you found a solution.
参考
カテゴリ
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!