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 CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by