Solved

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

Posted on 2006-06-27
5
132 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
ID: 16996255
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
ID: 17003650
Why don't you just use the load function??

a = load('file.dat')

=)
0
 

Author Comment

by:MaxEntropy
ID: 17009596
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
ID: 17011076
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
ID: 17011971
Adam, not yet...your suggesting looks most promising. Just need to confirm.
Max
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Baseline sigma 8 30
Probability Distribution 2 54
Error in calculation 2 60
Graph 5 71
Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

920 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