Give space after 3 digit
Show older comments
I am a new user of Matlab. So, a kind response will be highly appreciated.
All of my experimental data are saved into a txt file. Now, when I load the file, it gives me only one row without any tab or space. I need to separate the integers. A simple space after 3 integer will do the work. But, the file is huge. It's length is 1182239.
i.e: the data: 008112132143... I want: 008 112 132 143...
Accepted Answer
More Answers (2)
Matt J
on 22 May 2013
0 votes
See DLMWRITE and DLMREAD
Walter Roberson
on 22 May 2013
Read in the row as a string, say S.
If you want the result as strings, then
reshape(S, 3, []).'
would give one group of three per row.
If you want the result as integers converted from the strings, then
(S(1:3:end)-'0') * 100 + (S(2:3:end)-'0') * 10 + (S(3:3:end)-'0')
will give you a row vector of integral values.
Categories
Find more on Data Type Conversion 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!