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?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 3월 22일
out = nanmean(ArrDelay);
or in MATLAB R2015a
out = mean(ArrDelay,'omitnan'));

댓글 수: 6

How to read that column from '2004.csv' file into matlab workspace without using import? My version is MATLAB R2014a. Thank you so much! :)
ArrDelay = csvread('2004.csv')
Can I use the variable name of 'ArrDelay' to specify the column I want to read? Or I need to use the index of the column (14th)?
I tried ArrDelay = csvread('2004.csv', 1, 14)
I got several error messages:
Error using dlmread (line 138)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 17u) ==> ORD,CLT,599,7,11,0,,0,0,0,0,0,0\n
Error in csvread (line 47) m=dlmread(filename, ',', r, c);
Error in bigmean (line 2) ArrDelay = csvread('2004.csv', 1, 14);
How can I deal with it?
Please attach your csv-file
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)
I attached the sample of the csv file. Please have a look. Thanks in advance!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

질문:

2015년 3월 22일

댓글:

2015년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by