Extracting data from a text file into an array

조회 수: 12 (최근 30일)
BlueSky
BlueSky 2015년 11월 16일
편집: Stephen23 2019년 6월 19일
I have a large text file, I know how to get to the line that I want to extract the data from. The line contains thousands of numbers in the form:
Data1 x1 y1 z1 x2 y2 z2
Data2 x3 y3 z3 x4 y4 z4
I want Data1 to be the name of a new nx3 array and every number that comes after Data1 until the next Data2 to be stored under Data1 and so forth...
Any help/hints would be appreciated. Thanks.

답변 (2개)

Walter Roberson
Walter Roberson 2015년 11월 16일

Stephen23
Stephen23 2015년 11월 16일
편집: Stephen23 2019년 6월 19일
  댓글 수: 1
BlueSky
BlueSky 2015년 11월 20일
So, how do I pull those data values from the 1 line in the text file to a nx3 array? That is my issue. I can avoid dynamically naming those array but doing some sort of If statement and if it matches the name in the string I would assign it a name.
My issue is that the thousands of data points are on one single line in the text file, they're are also in the following format: Data1 {{x1 x2 x3} {r1 r2 r3}} Data2 {{x4 x5 x6} {r4 r5 r6}} Data3 {{x7 x8 x9} {r7 r8 r9}} ....and it goes on for thousands of data points.
I want to extract and put these data points in nx3 arrays: data1 = [x1 x2 x3; r1 r2 r3; x4 x5 x6; r4 r5 r6; x7 x8 x9; r7 r8 r9]
Does this explain my need better? Please help. Thanks.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by