Read the third column of a .csv file
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 26 Apr. 2022
give the option for decimal separator being ','
Alex Perrakis
am 26 Apr. 2022
Akzeptierte Antwort
Weitere Antworten (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)
Kategorien
Mehr zu Text Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!