Reading file starting at end in MATLAB -


i wondering if knows how open , read file in matlab begin reading end of file. file being updated (at nonconstant rate between reads) , want read last 6 lines of file each time.

i include test verify don't reread same lines twice. each line formatted follows (each variable floating point number):

timestamp accx accy accz gyrox gyroy gyroz magx magy magz 

i trying use fseek, change position last line of file, allows me read last line of file think, not read file backwards unless specify number of bytes, wouldn't know number of bytes exactly.

if you're on unix based system (linux/mac), can directly use system commands want. here's sample test file:

12345 accx accy accz gyrox gyroy gyroz magx magy magz 23456 accx accy accz gyrox gyroy gyroz magx magy magz 34567 accx accy accz gyrox gyroy gyroz magx magy magz 45678 accx accy accz gyrox gyroy gyroz magx magy magz 56789 accx accy accz gyrox gyroy gyroz magx magy magz 67890 accx accy accz gyrox gyroy gyroz magx magy magz 

you can read using tail on unix , matlab directly using system command.

[~, str]=system('tail -n 2 filename') str =      56789 accx accy accz gyrox gyroy gyroz magx magy magz     67890 accx accy accz gyrox gyroy gyroz magx magy magz 

replace 2 in -n 2 how many ever lines want read.

next, make sure read same line, might want store timestamps (first column). simplest way again let unix you

[~, timestamp]=system('tail -n 2 filename | awk ''{print $1}''')  timestamp =  56789 67890 

convert numbers using str2num , store these each time read , use function ismember check if new timestamp part of read timestamps.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -