필터 지우기
필터 지우기

messy table in one column

조회 수: 2 (최근 30일)
Birsen
Birsen 2017년 4월 27일
답변: Prannay Jain 2017년 5월 1일
Hi, I have a data with some strings and mostly numeric data. The strings are located in the first 11 lanes and then the numeric data is as follows ( that is the pattern until the end of the file). I just would like to get the numeric data but since the number of columns change in each line I have difficulties doing this. I tried many things (textscan, fopen, importdata etc) and I ended up using table with text option.
T1=readtable(fileName, 'FileType', 'text');
T2=T2(11:end,1);
However whatever I do I bumped into another problem and I ended up to have only one column. I can not the access the individual data since it is in the string format. I can not generate variable names neither since it is only one column. Any advice or solution is appreciated.
=== here is the one column data I ended, and I would like to save this part into another table ===
'1171 4000 24'
'4000 7 6000 2 1 12 2 2'
'-0.40695E+01 -0.27921E+01 -0.10915E+02 -0.49148E+00 -0.30083E-01 0.87037E+00 0.18997E+00 0.10000E+01 0.22955E+02'
'4000 7 1001 2 1 12 2 3'
'-0.49538E+01 -0.28463E+01 -0.93488E+01 0.12346E+00 -0.52177E+00 0.84411E+00 0.90250E-01 0.10000E+01 0.23253E+02'
Birsen
  댓글 수: 1
Image Analyst
Image Analyst 2017년 4월 27일
Attach the file if you want people to try things.

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

답변 (1개)

Prannay Jain
Prannay Jain 2017년 5월 1일
To skip first 11 lines which have string, you can use,
readtable(fileName, 'HeaderLines', 11)
'readtable' expects to have the same number of columns for every row it is reading. If data is not available for some column then make it blank by providing the delimiter which you are using in your file. Providing the proper delimiter for missing values will give the expected results and convert missing values to NaN. For example,
1 45 45 2 5
4 41 56 5
34 3
will be convertrd to,
Var1 Var2 Var3 Var4 Var5
____ ____ ____ ____ ____
1 45 45 2 5
4 41 56 NaN 5
NaN 34 NaN NaN 3

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by