read csv file with dates and numerical in R2016b

I have a csv data file like this:
2014-01-01 01:30:00,5.728,100.0,
2014-01-01 02:00:00,5.892,100.0,
2014-01-01 02:30:00,6.0120000000000005,100.0,
2014-01-01 03:00:00,5.982,100.0,
2014-01-01 03:30:00,6.122999999999999,98.277,
2014-01-01 04:00:00,6.02,98.09,
2014-01-01 04:30:00,5.763999999999999,97.54899999999999,
2014-01-01 05:00:00,5.406000000000001,96.83200000000001,
2014-01-01 05:30:00,5.162999999999999,96.961,
2014-01-01 06:00:00,5.109,97.315,
Is there any way to import both the dates and numerical values?
Thank you

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 4월 30일

0 개 추천

댓글 수: 7

it doesn't work on R2016b
Cris LaPierre
Cris LaPierre 2021년 4월 30일
편집: Cris LaPierre 2021년 4월 30일
Sure it does. I tested it in R2016a using the file snippet you shared above before suggesting it.
What are you seeing that makes you think it doesn't work? If there is an error message, please share the full message (all the red text). Consider sharing your file so we can test it. You can attach it to your post using the paperclip icon.
I've always got the same error when using readtable, and I found this (unsolved) in several posts
Error using textscan
Unknown parameter 'BufSize'.
Error in readtable>readtable_tlm (line 128)
data = textscan(fid, format_str, ...
Error in readtable (line 17)
[data, headers] = readtable_tlm(uncompressed, varargin{:});
I'm not familiar with this error, and haven't been able to reproduce it on my end. I could be more helpful if I had a sample file of yours to test with.
I'm attaching a subset of my dataset
Thank you very much
I get an odd character at the beginning of the first line that is messing up my attempts to read this file in. I was trying to use textscan to just see if I could read in the file.
fid = fopen('sample.csv');
out = textscan(fid,'%q')
fclose(fid)
thank you for your help

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jeremy Hughes
Jeremy Hughes 2021년 4월 30일

0 개 추천

Try this:
opts = detectImportOptions(filename)
T = readtable(filename,opts);

댓글 수: 2

After looking more closely at this file that won't exactly work, it's problematic since each line starts with a double quote character. To "correctly" read CSV formats you have to take everything between the quotes, this will read each line into a separate row without considering the commas.
Where does the file come from? Is it produced by other software, or just a file you have?
thank you for your help

댓글을 달려면 로그인하십시오.

제품

릴리스

R2016b

질문:

2021년 4월 30일

댓글:

2021년 5월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by