messy table in one column

3 views (last 30 days)
Birsen
Birsen on 27 Apr 2017
Answered: Prannay Jain on 1 May 2017
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 Comment
Image Analyst
Image Analyst on 27 Apr 2017
Attach the file if you want people to try things.

Sign in to comment.

Answers (1)

Prannay Jain
Prannay Jain on 1 May 2017
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

Community Treasure Hunt

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

Start Hunting!

Translated by