필터 지우기
필터 지우기

Removing all non NaN Values to a new matrix.

조회 수: 51 (최근 30일)
BdS
BdS 2020년 2월 5일
답변: BdS 2020년 2월 5일
Hi,
I have got a 261x3733 double array temp with numbers and NaN.
I would like to get in matrix a only the nonnan values. Conditions: a should be of the same size as temp and all nonnan values shouldn't change place.
I tried this code:
a=temp(~isnan(temp))
However I get the vector with size 330227x1
Do you have any suggestions for solving this issue?
  댓글 수: 2
Adam
Adam 2020년 2월 5일
What you want in place of the NaNs? You can't have nothingness is elements of a numeric array. If you extract only the non-nan values then you inevitably loose the shape of the matrix.
BN
BN 2020년 2월 5일
I'm Agree with Adam.
So you want to remove NaN and save the result in a new matrix BUT you want a new matrix to have exactly the same size as an original matrix?
What do you want to instead of NaN?
This data seems to be the temperature. You can fill them using the nearest station linear regression or using fillmissing function.

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

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2020년 2월 5일
a solution:
a=sparse(temp)
a(isnan(a))=[]

추가 답변 (2개)

BdS
BdS 2020년 2월 5일
I would like to apply the function winsorising on the elements with values only. The function winsorising accounts unfortunatelly for NaN elements.
  댓글 수: 1
Adam
Adam 2020년 2월 5일
I don't know what the function is, but can you not just pass the non-nan values to it and then if you want the result in your matrix you can put the results back in to the non-nan locations of a new result matrix.

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


BdS
BdS 2020년 2월 5일

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by