csvread doesn't work, I just get errors.
25 次查看(过去 30 天)
显示 更早的评论
I'm trying to import data from a data logger in csv format, this site says
"M = csvread('FILENAME',R,C)" is how you do that but I tried "m=csvread('LOGGER02.CSV',C5); disp(m);", but all I get is
Undefined function or variable 'C5'.
Error in untitled (line 1) m=csvread('LOGGER02.CSV',C5);
whats the real way to read csv files, assuming Matlab can read/import them? I'm using R2017b
0 个评论
回答(2 个)
Aarti Dwivedi
2018-7-24
R = 1
C5 = 1
m=csvread('LOGGER02.CSV',R, C5); disp(m);
The error is pretty straightforward that your variable definitions are missing. Just saying C5 doesn't mean that the cell address is C5. C5 is the name of the variable in which you will store the column offset.
19 个评论
Walter Roberson
2018-7-25
The simplest way is
t = readtable('LOGGER02.CSV', 'HeaderLines', 1, 'ReadVariableName', false);
temperature = t{:,2}; %or as appropriate
humidity = t{:,4}; %or as appropriate
If you have R2016b or later, you can use detectImportOptions and set the SelectedVariables property to cause it to throw away everything else when you use readtable()
For older versions of MATLAB, before R2013b, then probably it would be best to use fopen()/textscan()/fclose() . This requires knowing the format of the columns you are skipping.
Image Analyst
2018-7-24
If "C5" is the column/row you see when you open it in Excel, then row = 5 and column = 3, and csvread() expects integers for offsets, not actual row or column numbers (i.e. 4 and 2):
Starting row offset, specified as a nonnegative integer. The first row has an offset of 0.
Starting column offset, specified as a nonnegative integer. The first column has an offset of 0.
so try
m=csvread('LOGGER02.CSV', 4, 2);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!