Read the third column of a .csv file
Mostra commenti meno recenti
Hello Guys and Girls,
i have following .csv file and i am trying to import only the 3rd column which is a temperature. The problem is that although i read it with readtable for some reasons my delimiter does not work and it shows the time and temperature in one cell
My code until now is as follows:
URL = uigetdir('C:\_Daten\Messungen\');
measurements = dir(URL); measurements(1:2) = [];
file=fullfile( URL, measurements.name);
fid = fopen(file, 'rt');
%a = textscan(fid, '%{yyyy-MM-dd}D %{hh:mm:ss.SSS}T %f ','Delimiter',' ');
A=readtable(file,'Format','%s%s%n','Delimiter',' ');
B=table2array(A(:,2));
C=split(B,' ');
% B=table2array(A(:,3));
% Data = str2double(strrep(B, ',', '.'));
% format short g
fclose(fid);
Thanks very much for the help!
2 Commenti
Walter Roberson
il 26 Apr 2022
give the option for decimal separator being ','
Alex Perrakis
il 26 Apr 2022
Risposta accettata
Più risposte (1)
Another option which requires less of a custom function but still use the 'detectImportOptions' is to specify in your detectImportOptions that the decimal separator is comma
opts = detectImportOptions('MS1.csv','DecimalSeparator',',');
datatable = readtable('MS1.csv',opts);
head(datatable)
Categorie
Scopri di più su Text Files in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!