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

4 views (last 30 days)
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>

Answers (1)

Walter Roberson
Walter Roberson on 22 Feb 2021
nnz(isnan(text1{7})
  1 Comment
Sarah Mullin
Sarah Mullin on 22 Feb 2021
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'."

Sign in to comment.

Categories

Find more on Numeric Types in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!