Organizing Messy Notepad data

조회 수: 5 (최근 30일)
Matlabbey
Matlabbey 2012년 7월 23일
댓글: Walter Roberson 2015년 2월 28일
I have some data in Notepad that is a mess. It's a .txt file.There is basically no space between any of the different columns which hold different data. I know the spaces for the data. For example, Columns 1-2 are X, Columns 7-10 are Y....
How can I organize this? Can it be done in R? What is the best way to do this?
Thanks!!

답변 (2개)

Jason Ross
Jason Ross 2012년 7월 23일
편집: Jason Ross 2012년 7월 23일
I would do it in a regular expression. Take a look at the "Positional" and "Lookaround" operators:
You should be able to get the first columns and second columns this way without a problem.
You can do this in whatever language you want, as long as it supports regular expressions -- M, Perl, shell (sed/awk), etc. The actual syntax will vary depending on which on you pick.
You could also do this without regular expressions, counting character places, but you might need to do some transformations of the data type.
The "best" way is the one that works with whatever you are doing with the data next. Ideally, the output will be in a format that is readily useful to the next processing step.

Albert Yam
Albert Yam 2012년 7월 23일
편집: Albert Yam 2012년 7월 23일
For general cases, Jason's response is probably the way to go.
But if the information is delimited, you can try http://www.mathworks.com/help/techdoc/ref/dlmread.html.
Edit. Actually, if you know the columns, and they are consistent. You can load into EXCEL and "Text to Columns" with fixed width. Then load that into Matlab.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by