필터 지우기
필터 지우기

How to ignore NaN values in the CORR Function?

조회 수: 259 (최근 30일)
André Gadêlha
André Gadêlha 2018년 1월 26일
답변: Star Strider 2018년 1월 26일
Hi Guys,
My problem is the opposite of the other problems reported here between NAN values in CORR function.
If I have a matrix A = [1;2;3;4] and a matrix B = [3;5;7;8], the correlation corr(A,B) is 0.9898.Ok for that.
But, If there is a NaN value in B, such as: B = [3;5;7;NaN], the correlation corr(A,B) will be NaN instead of 1.0000 (that is the correlation of the not NaN values of A (1;2;3) and B(3;5;7).
What can I do to make it calculate the corr function ignoring this NaN values making it give me answers different of "NaN"?

답변 (1개)

Star Strider
Star Strider 2018년 1월 26일
Use the 'rows','complete' name-value pair to ignore rows with NaN values:
A = [1;2;3;4]
B = [3;5;7;NaN];
R = corr(A,B, 'rows','complete')
R =
1.0000

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by