How to load a specially formatted data file into matlab?
3 views (last 30 days)
Show older comments
I need to load a data file, test.dat, into Matlab. The contents of data file are like
*a682 1233~0.2
*a2345 233~0.8 345~0.2 4567~0.3
*a3457 345~0.9 34557~1.2 34578~0.2 9809~0.1 2345~2.9 23452~0.9 334557~1.2 234578~0.2 19809~0.1 23452~2.9 3452~0.9 4557~1.2 3578~0.2 92809~0.1 12345~2.9 232452~0.9 33557~1.6 23478~0.6 198099~2.1 234532~2.9 …
How to read this type of file into matlab, and use the terms, such as *2345 to identify a row, which links to corresponding terms, including 233~0.8 345~0.2 4567~0.3
Thanks.
0 Comments
Accepted Answer
Walter Roberson
on 7 Sep 2011
Please expand on this. For example, the first line:
*a682 1233~0.2
How would you like that to be stored in MATLAB?
Is the character in-between always the tilde character? Do the numbers always occur in pairs with the ~ between them? Do negative numbers ever occur? Do you want the pairs stored as a string or as a vector of two numeric values with the ~ left out? Is there ever a decimal point in the number before the ~ or is always an integer?
Should
*a2345 233~0.8 345~0.2
become {'*a2345' [233 0.8] [345 0.2]} or should it become {'*a2345' [233] [0.8] [345] [0.2]} or should it become {'*a2345' [233 0.8 345 0.2]} or something else?
0 Comments
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!