Solved

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

Posted on 2006-06-27
5
135 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2k Power n formula 2 39
Triangle - calculating angles 9 73
Calculating Percentile Value inside Excel. 2 89
Understanding factorial 4 31
Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
How to Win a Jar of Candy Corn: A Scientific Approach! I love mathematics. If you love mathematics also, you may enjoy this tip on how to use math to win your own jar of candy corn and to impress your friends. As I said, I love math, but I gu…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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