Pearsons correlation using corrcoef not working
3 ビュー (過去 30 日間)
古いコメントを表示
I am trying to calculate the pearsons correlation between two variables in a timetable. I am utalising the corrcoef() function. However the output it gives me is always NaN NaN NaN NaN. Why is this? How can I fix this?
4 件のコメント
William Rose
2021 年 3 月 24 日
Are the variables (vectors) which you are trying to correlate both numbers (not strings or times or dates), with the same length?
If you provide the timetable, and the code that does not work, as attached files, it will help others help you. An example of corrcoeff() operating on two columns from a table is below.
>> height=1.7+0.2*randn(10,1);
>> weight=70+10*randn(10,1);
>> T=table(height,weight);
>> corrcoef(T.height,T.weight)
ans =
1.0000 0.2262
0.2262 1.0000
採用された回答
William Rose
2021 年 3 月 24 日
X = rand(10, 4);
X(X < 0.1) = NaN;
disp(X); %array containing NaNs
X(any(isnan(X), 2), :) = []; %delete rows with NaN
disp(X) %array with NaN rows removed
1 件のコメント
William Rose
2021 年 3 月 24 日
Assumng your input data are column vectors, you would do
%make a Nx2 array
A=[combined_data.Observed_Rio_Branco,combined_data.Simulated_Rio_Branco];
A(any(isnan(A), 2), :) = []; %delete rows with NaN
NSE(A(:,1),A(:,2));
I do not have the NSE() function so I cannot test the code above.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!