MATLAb creating variables from ascii document

  • Context: MATLAB 
  • Thread starter Thread starter gryphon1221
  • Start date Start date
  • Tags Tags
    Matlab Variables
Click For Summary

Discussion Overview

The discussion revolves around importing data from an ASCII document into MATLAB variables. Participants are exploring methods to extract specific data points (X, Y, Z, and time) from a formatted text file that includes header information followed by data entries.

Discussion Character

  • Technical explanation, Exploratory, Debate/contested

Main Points Raised

  • One participant describes the format of the data and seeks advice on how to import it into MATLAB variables.
  • Another suggests using regular expressions to read each line and split the data based on spaces.
  • A different participant believes there might be a more straightforward command that can accomplish the task in one step but cannot recall it.
  • One participant proposes using the fscanf function, provided that each line of data is identical.
  • Another participant recommends using the dlmread function, indicating it is simpler than fscanf and suggesting to skip the initial header rows and the first column.

Areas of Agreement / Disagreement

Participants present multiple competing views on the best method to import the data, with no consensus reached on a single approach.

Contextual Notes

There are assumptions about the uniformity of the data lines and the structure of the ASCII document that remain unverified. The discussion does not resolve which method is optimal for the given task.

Who May Find This Useful

Individuals working with MATLAB who need to import data from ASCII files, particularly those with similar formatting challenges.

gryphon1221
Messages
9
Reaction score
0
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.
 
Physics news on Phys.org
read each line, break it up on a blank space using regular expressions and put each entry into the correct variable.
 
I'm pretty sure there's an easier way. A command that does it in one hit. But I forget.
 
if each line is identical, can us a fscanf(...);
 
I this case you can use dlmread
Much easier than fscanf etc

Just skip the.initial rows( the header) and the first column.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K