How to hadle NAN data of csv file

3 ビュー (過去 30 日間)
Tahir
Tahir 2014 年 11 月 3 日
回答済み: Chad Greene 2014 年 11 月 3 日
Hi, I read an excel file...now i want to one by one take the x values and y values from that excel file.....The x values are at the first column,and y value are in the second column..and similrly again x value at 3rd column and y value at fourth column.here is the code...but problem is the NAN data in file.
how to skip NAN data of file.i am also attaching the file here. there are 25 files so the loop.
for i=1:25
clear file;
file = xlsread(strcat('TrainingDataset\', num2str(i) , '.csv'));
x=file(:,1:2:end)
y=file(:,2:2:end)
average_x=mean(x(:))
average_y=mean(y(:))
end

回答 (1 件)

Chad Greene
Chad Greene 2014 年 11 月 3 日
Three possible solutions:
1. If you have the Statistics Toolbox,
average_x = nanmean(x(:));
2. If you download the nan suite from FEX,
average_x = nanmean(x(:));
3. If you prefer to ignore the NaNs yourself,
average_x = mean(x(isfinite(x(:))));

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by