Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:46:25+00:00 2026-05-23T12:46:25+00:00

I was wondering if anyone knows how to open and read from a file

  • 0

I was wondering if anyone knows how to open and read from a file in MATLAB where you begin reading from the end of the file. The file is constantly being updated (at some nonconstant rate between reads) and I want to read the last six lines of the file each time.

I would also to include a test to verify that I don’t reread the same lines twice. Each line is formatted as follows (each variable is a floating point number):

timestamp accx accy accz gyrox gyroy gyroz magx magy magz

I was trying to use fseek, to change the position to the last line of the file, but this only allows me to read the last line of the file I think, not read the file backwards unless I specify a certain number of bytes, which I wouldn’t know the number of bytes exactly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:46:26+00:00Added an answer on May 23, 2026 at 12:46 pm

    If you’re on a unix based system (Linux/Mac), you can directly use system commands to do what you want. Here’s a 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 it using tail on unix and into MATLAB directly using the 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 the 2 in -n 2 with how many ever lines you want to read.

    Next, to make sure you read the same line, you might want to store the timestamps (first column). The simplest way to do that is again let unix do it for you

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

    Convert it to numbers using str2num and store these each time you read and then use the function ismember to check if a new timestamp is already part of your previously read timestamps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone knows of any good Open Source distributed computing projects?
Just wondering if anyone knows of an open source .Net library that handles dates
i was wondering if anyone knows how yelp determines what restaurants are open now?
I'm wondering if anyone knows of some tricks for rewriting the paths of web
I am wondering if anyone knows of an open source c# library for beautifying
I was wondering if anyone knows of any good open source app templates out
I was wondering if anyone knows of any open source applications that are using
I was wondering does anyone know if its possible to open a wifi and
Just wondering whether anyone knows how to get blogger labels into alt tags in
I was wondering whether anyone knows definitively if LINQ to SQL has the capability

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.