Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

rearranging textfile that contains commas

1 vue (au cours des 30 derniers jours)
Kafayat Olayinka
Kafayat Olayinka le 11 Mar 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
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

Réponses (1)

Gareth
Gareth le 11 Mar 2019
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');

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by