Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-27
5
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 …
This article seeks to propel the full implementation of geothermal power plants in Mexico as a renewable energy source.
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…
Suggested Courses

609 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