Solved

Matlab Programming Language Question: How to read part of txt file into a matrix

Posted on 2006-06-27
5
127 Views
Last Modified: 2016-02-10
Hi, it's been a while since I've used Matlab, so bare with me.

I am running Matlab 7.2.0.232 on WindowsXP.

I have a txt file and I want to read part of that text file into a matrix.

Here is an example of the text in the text file:

lines of text of variable length and content...
lines of text of variable length and content...
lines of text of variable length and content...

{c0 c1    c2    c3  c4  c5    c6    c7    c8    c9  c10 c11 c12 c13 c14 c15 c16
 1  float float int int float float float float int int int int int int int int
 2  float float int int float float float float int int int int int int int int
 3  float float int int float float float float int int int int int int int int
 .
 .
 .
 .
 N  float float int int float float float float int int int int int int int int}
EndOfFile;

I want to read the part between the braces ({ }) into a matrix (note that the braces are not in the txt file...I am using them here for id purposes only).  The first row are colmumn headers. The first number in every row is a row id from 1 to N, where N is the total number of rows. N is a variable and can be any where from 1 to 1,000,000, but is usually around 10,000. The number of columns is fixed at 17.

Once I have the data into a matrix I can manipulate it.

Thanks in advance,
Max
0
Comment
Question by:MaxEntropy
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
Comment Utility
There are several functions that might help...
The best for this type of file would probably be:   data=dlmread('filename',delimeter,R,C)
where
    'filename'    is the file to read
    delimeter    is the delimeter seperating fields (eg: space, tab, comma)
    R, C           Row and Column to start reading

0
 
LVL 4

Expert Comment

by:e_tadeu
Comment Utility
Why don't you just use the load function??

a = load('file.dat')

=)
0
 

Author Comment

by:MaxEntropy
Comment Utility
e_tadeu, that won't work because the data that i want to import into a matrix is embedded in a text file with other text.
Thanks,
Max
0
 
LVL 39

Expert Comment

by:Adam314
Comment Utility
Have you tried the dlmread function.

Set R to the number of rows to skip... so if you have 10 lines of text before your real data, set R to 10.
0
 

Author Comment

by:MaxEntropy
Comment Utility
Adam, not yet...your suggesting looks most promising. Just need to confirm.
Max
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server - Query for Outlier 11 49
Adjust number proportionately 12 63
Random Variable 2 38
Revenue table 8 70
This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now