Info
此问题已关闭。 请重新打开它进行编辑或回答。
rearranging textfile that contains commas
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a textfile that looks like the following. The text breaks at the end of the 25th typed space
date,time,lat,long,alt
itude,pressure
03/10/2019,12:00,23,-6
0,1000,955
03/10/2019,13:00,23,-6
3,980,900
03/10/2019,14:00,23,-6
3,600,850
03/10/2019,15:00,23,-6
3,800,950
03/10/2019,16:00,23,-6
0,500,750
part of variable "altitude" breaks into "altitu"./n "de"
also part of variable longitude data breaks into "-6" ./n "3".
how can i write a code that put longitude date together as "-63"?
how can i write the delimiter for this problem?
thanks
0 个评论
回答(1 个)
Gareth
2019-3-11
There is probably an easier way of doing this... but this should work:
a = fileread('example.txt'); % txt file that you shared
b = double(a);
c = b==10; % \n in ASCII code, it could be that you need to do the same for \r\n (depending on your OS)
d = cumsum(c);
e = mod(d,2);
b(c&e) = []; % remove every second \n
f = char(b); % string now clean
formatSpec = '%{dd/MM/uuuu}D%{hh:mm}D%f%f%f%f';
delimiter = ',';
dataArray = textscan(f, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'HeaderLines' ,1, 'ReturnOnError', false, 'EndOfLine', '\n');
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!