I want to read only the numbers from the text file between a range ( were the start and end differs constantly from one txt file to another)
2 ビュー (過去 30 日間)
古いコメントを表示
I want to read only the numbers from a txt file ( attached) by skipping the first few lines which are not needed till the end of the file(always skipping the last two lines)
for example
We read the first letter of every line in the file.
if the line starts with an alphabet i want it to be skipped and read it when it has a number as it's first letter.
So that eventually i will automatically get the range of the lines i want ,( from were the values start and end) automatically.
6 件のコメント
dpb
2014 年 7 月 30 日
Me no follow -- once you have the desired lines parsed, then just convert to numeric --
v=str2num(char(file));
Now you've got a Nx3 array of the values to do whatever you wish with.
採用された回答
dpb
2014 年 7 月 30 日
Complete comments in one place...
Or, simply read the full file in as text and eliminate the lines unwanted in memory. May well be faster overall than fgetl reading/parsing line-by-line.
file=textread('yourfile.txt','%s','delimiter','\n','whitespace','');
gives a cell array, one element/line. To eliminate the lines w/ initial alphabetic characters leaving the numeric ones,
isdigit=isstrprop(char(file),'digit'); isdigit=isdigit(:,1);
file=file(isdigit);
Used the intermediary logical array since can't use subscripting on expression results, unfortunately. Can do same operation w/ cellfun if prefer that route.
v=str2num(char(file));
Now you've got a Nx3 array of the values to do whatever you wish with.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
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!