Reading selected data from .dat file
2 views (last 30 days)
Show older comments
Hello,
I'm trying to extract data from a .dat file in a particular way. Basically, I need my program to take points from the first part of the data file...
1 8 12 13 14 9 3 2
3 9 14 15 16 10 5 4
.... (and so on)
and select data from the next part of the file corresponding to the numbers above as an "index."
2.0000 0
1.9829 0.1305
1.9319 0.2588
1.7321 0.5000
1.4142 0.7071
0.7654 0.9239
0.0000 1.0000
2.2000 0
As a for instance,
The first line of my file starts with "1 8 12 13..." I need to get coordinates:
2.0000 0
2.2000 0
.. and so on (coordinates corresponding to lines 12 and 13 and on..)
Just imagine it indexed like so,
1. 2.0000 0
2. 1.9829 0.1305
3. 1.9319 0.2588
4. 1.7321 0.5000
5. 1.4142 0.7071
6. 0.7654 0.9239
7. 0.0000 1.0000
8. 2.2000 0
If there is a more efficient way to perform this, please share!
0 Comments
Answers (1)
Star Strider
on 7 May 2016
Use the ‘First Part’ as indices into the ‘Second Part’.
For example:
FirstPart = [1 8 12 13 14 9 3 2];
NextPart = [2.0000 0
1.9829 0.1305
1.9319 0.2588
1.7321 0.5000
1.4142 0.7071
0.7654 0.9239
0.0000 1.0000
2.2000 0];
Result = NextPart(FirstPart(1:2),:)
Result =
2.0000 0.0000
2.2000 0.0000
Use all of ‘FirstPart’ in your code. I just used ‘FirstPart(1:2)’ because that’s all we have to work with.
0 Comments
See Also
Categories
Find more on Data Import and Analysis 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!