Read one column from a csv file into MATLAB for calculating

1 view (last 30 days)
I'd like to read one column from a csv file '2004.csv' which already in the MATLAB path. The column contains 'NaN' value and I want to treat it as empty. The column looks like following:
ArrDelay
NaN
-14
2
14
-6
NaN
11
57
...
-6
NaN
11
57
The variable name is 'ArrDelay' which is the title of the column. The column contains 7009729 records and I'd like to calculate the mean of those records.
How can I make it?

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 22 Mar 2015
out = nanmean(ArrDelay);
or in MATLAB R2015a
out = mean(ArrDelay,'omitnan'));
  6 Comments
Xiaoqing Zhuang
Xiaoqing Zhuang on 22 Mar 2015
The data set is very large and it doesn't allow me to attach here. I can describe it.
The column I need combines string 'NaN' and integers. There are A to AC columns (29 columns). The column needed is 15th. There are 7009729 rows(the first row is title for each column, it is string. Tile for the 15th is 'ArrDelay').
Purpose: calculate mean of that column.
I just tried following codes, it failed.
tic
ArrDelay = csvread('2008.csv', 1, 14, [1,14,7009729,15]);
meanresult = nanmean(ArrDelay);
sprintf('%g.\n',toc)
Xiaoqing Zhuang
Xiaoqing Zhuang on 22 Mar 2015
I attached the sample of the csv file. Please have a look. Thanks in advance!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!