How do I count how many NaN's in a data cell?

2 次查看(过去 30 天)
I was given a csv file by my teacher to download and i read it using this code below:
clear;
fclose all;
fileID = fopen('accidents_2017.csv');
text1 = textscan(fileID,'%s%s%s%s%s%s%d%d%s%d%d%d%d%f%f','HeaderLines',1,'Delimiter',{','},'EmptyValue',NaN);
fclose(fileID);
I tried using the function isnan(text1) but it tells me "Undefined function 'isnan' for input arguments of type 'cell'. " Is there a different function I should be using>

回答(1 个)

Walter Roberson
Walter Roberson 2021-2-22
nnz(isnan(text1{7})
  1 个评论
Sarah Mullin
Sarah Mullin 2021-2-22
Will this only work for columns that are numerical values? I tried converting column 1(which are strings) to numbers with str2double(text1{1}) and it worked. then when i do nnzisnan(text1{1}) it gives me the error of "Undefined function 'isnan' for input arguments of type 'cell'."

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by