Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAb creating variables from ascii document

  1. Nov 20, 2011 #1
    Hi, I have a document with a whole bunch of header information and description. After about 20 lines it goes into the useful data. Each line of data is formatted like this:

    P 1 1234.939 1234.505 1234.505 102

    where P just denotes that it is data, 1 is a satellite number and the data is X Y Z and time.

    Does anybody know how to import this data into useful variables X Y Z and time? I am thinking it will be textscan or something, but I have never used data in this format before. Thanks for any help.
     
  2. jcsd
  3. Nov 20, 2011 #2

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    read each line, break it up on a blank space using regular expressions and put each entry into the correct variable.
     
  4. Nov 21, 2011 #3
    I'm pretty sure there's an easier way. A command that does it in one hit. But I forget.
     
  5. Nov 24, 2011 #4

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    if each line is identical, can us a fscanf(.....);
     
  6. Nov 24, 2011 #5

    f95toli

    User Avatar
    Science Advisor
    Gold Member

    I this case you can use dlmread
    Much easier than fscanf etc

    Just skip the.initial rows( the header) and the first column.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook