Reading large data set from text file & separating to individual column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Poulomi Ganguli
am 11 Aug. 2017
Beantwortet: Andrei Bobrov
am 11 Aug. 2017
Hello, I have a text file in foll. format:
1950/05/21 04:00:00 1.7100 1 1
1950/05/21 05:00:00 1.5500 1 1
1950/05/21 06:00:00 1.4000 1 1
1950/05/21 07:00:00 1.2200 1 1
I need to separate it to individual column elements. The desired output is as below:
1950 05 21 04 1.71 1 1
1950 05 21 05 1.55 1 1
1950 05 21 06 1.40 1 1
1950 05 21 07 1.22 1 1
Please suggest codes for this. Thanks
0 Kommentare
Akzeptierte Antwort
José-Luis
am 11 Aug. 2017
Bearbeitet: José-Luis
am 11 Aug. 2017
Read in your data and then:
dummy = '1950/05/21 04:00:00 1.7100 1 1';
result = regexprep(dummy,'[\s/:]+',' ')
If you just want to edit a text file like that, there probably are better tools than Matlab for that. grep, for instance.
0 Kommentare
Weitere Antworten (2)
KSSV
am 11 Aug. 2017
T = readtable('data.txt') ;
T = table2cell(T) ;
dt = strcat(T(:,1), '/',T(:,2)) ;
T = [dt T(:,3:end)] ;
iwant = [datevec(T(:,1)) cell2mat(T(:,2)) cell2mat(T(:,3)) cell2mat(T(:,4))]
0 Kommentare
Andrei Bobrov
am 11 Aug. 2017
T = readtable('doc.txt')
[a,b,c,d] = datevec(datetime(strcat(T{:,1},{' '},T{:,2}),'I','yyyy/MM/dd HH:mm:ss'));
out = [a,b,c,d,T{:,3:5}]
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Import and Export finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!