Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

rearranging textfile that contains commas

1 visualización (últimos 30 días)
Kafayat Olayinka
Kafayat Olayinka el 11 de Mzo. de 2019
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (1)

Gareth
Gareth el 11 de Mzo. de 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');

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by