How do I remove NaN's from my data?

조회 수: 30 (최근 30일)
Sarah Mullin
Sarah Mullin 2021년 2월 22일
댓글: Walter Roberson 2021년 2월 22일
I was given a csv file and I used this code below to read it:
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);
How do I plot this data? My teacher never gave a function of how to plot with data values. I already converted all the data into numbers using str2double(text1). What should I do?

답변 (2개)

the cyclist
the cyclist 2021년 2월 22일
If your numeric vector is called "x", then
x(isnan(x)) = [];
will remove the NaN values.
  댓글 수: 7
Image Analyst
Image Analyst 2021년 2월 22일
Try readmatrix() instead of fopen(), textscan(), and fclose().
Walter Roberson
Walter Roberson 2021년 2월 22일
As this is roughly the 4th or 5th posting on the same topic:
as far as I have been able to determined, this is an assignment and the poster is required to use textscan() with the format indicated, even though it is not the best tool.

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


Walter Roberson
Walter Roberson 2021년 2월 22일
Don't use
str2double(text1)
Use
str2double(text1{1})
replacing the 1 with 2, 3, 4, 5, 6, or 9 as needed (the column number to extract.)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by