?
Solved

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

Posted on 2006-06-27
5
Medium Priority
?
145 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction On a scale of 1 to 10, how would you rate our Product? Many of us have answered that question time and time again. But only a few of us have had the pleasure of receiving a stack of the filled out surveys and being asked to do somethi…
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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
Course of the Month12 days, 2 hours left to enroll

752 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