Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

rearranging textfile that contains commas

조회 수: 1 (최근 30일)
Kafayat Olayinka
Kafayat Olayinka 2019년 3월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

GT
GT 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');

Community Treasure Hunt

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

Start Hunting!

Translated by