Importing a CSV with Date/Time and Scientific Notation
Mostra commenti meno recenti
I am trying to write a code to import the output from Thorlabs Optical Power Meter (PM100USB with S120C sensor) at a series of locations from translation stages using Thorlabs Kinesis.
The CSV output from Optical Power Meter has been problematic, considering it has date, time, and scientific notiation values.
dlmread, shown below:
opt_n2_n2 = dlmread('sample_test_11.csv',';',16,1)
produces this error message:
% Error using dlmread (line 147)
% Mismatch between file and format character vector.
% Trouble reading 'Numeric' field from file (row number 1, field number 3) ==> /29/2019;09:52:19;2.268E-09\n
I have attached a sample of the output and shown below are a few other attempts that I have made to import the data, all of which have been unsuccessful.
%opt_n2_n2 = fileread('sample_test_11.csv')
%opt_n2_n2 = textscan('sample_test_11.csv','D16:D35')
fid = fopen('sample_test_11.csv', 'rt');
%C = textscan(fid,'%f%f%f%f','HeaderLines',6);
m = textscan(fid,'%f%f%f%s%s','HeaderLines',2, 'Delimiter',';');
fclose(fid);
%headers = string( strsplit( fgetl(fid), ';') );
%data = cell2mat( textscan(fid, '%f%f%f%f%f', 'Delimiter', ';', 'collectoutput', 15) );
I was successful at converting the csv to an Excel file and importing the data, but considering that each experiment will involve 64 csv files I would prefer to automate this process through Matlab. I was also able to force the optical intensity data through manually importing it through the workspace, but once again I would like to automate this process.
The utlimate goal after importing the data is to compile it into a single one column matrix/variable, then plot it as a surface. I was able to generate the surface plot, showing optical intensity based on position, after the Excel import.
Any advice on simplifying/automating this process for facilitated reproducibility would be very much appreciated! Please let me know if there are any questions, and thanks in advance!
1 Commento
Walter Roberson
il 29 Ott 2019
We recommend using readtable()
Using textscan() is also possible, but you should use %D format specifications to read the dates and times. Or at the very least you should add / and : to your list of delimiters and read 8 numbers per line
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Spreadsheets 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!