Read table using readtable with different number of spaces and delete unnesessary spaces

19 views (last 30 days)
My data is plain-text in the following format:
K L_1 L_2 N O
1 1 a1 3bD 1.72
2 1 2c 4Gd 1.43
3 1 e3 5Cf 1.33
4 1 g4 h5L 1.64
1 2 4i 4jA 1.48
2 2 6k lC8 na
3 2 m7 8nB na
4 2 o8 Ap0 1.43
In row seven and eight my data are separated by more than one space. This leads to an error using readtable. I would like to delete this spaces so that I can use the command readtable. How can I solve this problem?

Answers (1)

Peter Perkins
Peter Perkins on 22 Apr 2015
Thomas, if you provide a format string to readtable ('Format','%f%f%s%s%f' in your case, I think), you can also specify parameters for textscan. I think 'Delimiter',' ','MultipleDelimsAsOne',true will do what you want.

Categories

Find more on Cell Arrays 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!