Read the third column of a .csv file
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 26 de Abr. de 2022
give the option for decimal separator being ','
Alex Perrakis
el 26 de Abr. de 2022
Respuesta aceptada
Más respuestas (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)
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!