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)

4 ビュー (過去 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 件のコメント
Vinit
Vinit 2014 年 7 月 30 日
I have the cell with all the values thanks to you....the problem i have now... the data is like this .......0 1 2 3 0 1 2 3 0 1 2 3.. these are redings of time... how to i combine the times so that when i plot all of this will be of a same line........?
dpb
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
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 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by