MATLAb creating variables from ascii document

In summary, The conversation discusses importing data from a document that contains header information and useful data. The data is formatted in a specific way and the question is how to import it into variables. Suggestions are made to use regular expressions, fscanf, or dlmread to easily import the data. One person suggests skipping the initial rows and first column for easier importing.
  • #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.
 
Physics news on Phys.org
  • #2
read each line, break it up on a blank space using regular expressions and put each entry into the correct variable.
 
  • #3
I'm pretty sure there's an easier way. A command that does it in one hit. But I forget.
 
  • #5
I this case you can use dlmread
Much easier than fscanf etc

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

1. What is MATLAB and how does it create variables from an ASCII document?

MATLAB is a programming language and software environment commonly used in scientific and engineering fields. It allows users to create variables by importing data from various sources, including ASCII documents. This can be done using the "importdata" function, which reads the data from the document and creates a MATLAB variable with the same name.

2. Can MATLAB create variables from any type of ASCII document?

Yes, MATLAB can create variables from any type of ASCII document, including CSV, TXT, and DAT files. As long as the data is formatted in a way that MATLAB can understand, it can be imported and converted into a variable.

3. What is the benefit of creating variables from an ASCII document in MATLAB?

Creating variables from an ASCII document allows for easy manipulation and analysis of large datasets in MATLAB. It also eliminates the need for manual data entry, which can be time-consuming and prone to human error.

4. How can I access the variables created from an ASCII document in MATLAB?

The variables created from an ASCII document can be accessed like any other variable in MATLAB. They can be viewed in the Workspace window or used in calculations and functions within the MATLAB code.

5. Can I create and import multiple variables from an ASCII document in MATLAB?

Yes, you can create and import multiple variables from an ASCII document in MATLAB. The "importdata" function allows for specifying which columns or rows of data to import, making it possible to create multiple variables from one document.

Suggested for: MATLAb creating variables from ascii document

Replies
4
Views
439
Replies
4
Views
2K
Replies
1
Views
1K
Replies
1
Views
864
Replies
5
Views
908
Replies
2
Views
2K
Replies
32
Views
2K
Replies
2
Views
1K
Replies
2
Views
635
Back
Top