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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 30 Jul. 2014
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.
Akzeptierte Antwort
dpb
am 30 Jul. 2014
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!