How do I remove NaN and / or interpolated data?

조회 수: 23 (최근 30일)
Thaís Fernandes
Thaís Fernandes 2019년 1월 25일
댓글: Thaís Fernandes 2019년 1월 25일
Hello.
I have the vectors
A=[1 NaN 3 ;...
4 NaN 6 ;...
5 NaN NaN;...
0 NaN NaN;...
7 8 NaN;...
0 0 9] ;...
(variable A) and t=0:1:5; (time), and I would like to do the following: If in a column there are more than 4 rows with NaN I exclude this column, otherwise I interpolate this data.
I have no idea how to do this. Can anyone help me giving suggestions?
Thanks.

채택된 답변

Guillaume
Guillaume 2019년 1월 25일
A=[1 NaN 3
4 NaN 6
5 NaN NaN
0 NaN NaN
7 8 NaN
0 0 9]
%remove columns with more than 4 nans
A(:, sum(isnan(A), 1) >= 4) = [];
%replace nans by interpolated values. Requires R2016b or later
A = fillmissing(A, 'linear')
  댓글 수: 1
Thaís Fernandes
Thaís Fernandes 2019년 1월 25일
The 'fillmissing' function did not run on my version of my matlab. So I used the first part that you suggested and then the suggestion of another person on another question (see below) to interpolate.
Thank you for your help. :)
 
%To interpolate, I used
nanx = isnan (A);
  t = 1: numeral (A);
  A (nanx) = interp1 (t (nanx), A (nanx), t (nanx));

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by