Effacer les filtres
Effacer les filtres

csvread doesn't work, I just get errors.

19 vues (au cours des 30 derniers jours)
Hank Gunderson
Hank Gunderson le 24 Juil 2018
Commenté : Hank Gunderson le 27 Juil 2018
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

Réponses (2)

Aarti Dwivedi
Aarti Dwivedi le 24 Juil 2018
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 commentaires
Walter Roberson
Walter Roberson le 25 Juil 2018
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.
Hank Gunderson
Hank Gunderson le 27 Juil 2018
That works great thanks!

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 24 Juil 2018
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);

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by