Displays Nan in correlation result

조회 수: 1 (최근 30일)
Nirajan Khatri
Nirajan Khatri 2020년 9월 23일
댓글: Ameer Hamza 2020년 9월 24일
I am finding the correlation between the generated random variable but the result is nan, can you please help me
clear all;
clc;
N = 1000;
% standard normal distribution mean=0 and variance =1
norm_mean=0;
norm_var=1;
%generating random variable with standard normal distribution
r1= norm_mean+sqrt(norm_var)*randn(1,N);
r2= norm_mean+sqrt(norm_var)*randn(1,N);
%normal distribution PDF
xPDF= normpdf(r1,norm_mean,sqrt(norm_var));
yPDF =normpdf(r2,norm_mean,sqrt(norm_var));
%calculate normal distribution cdf
pd = makedist('Normal',norm_mean,sqrt(norm_var));
%compute the cdf values for the standard normal distribution at the values
%in random variables
y1 = cdf(pd,r1);
y2 = cdf(pd,r2);
%calculating correlation
rho= corr(r1,r2);
  댓글 수: 1
Nirajan Khatri
Nirajan Khatri 2020년 9월 23일
and i am trying to compute gaussian copula

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 9월 23일
r1 and r2 shoule be column vectors in your case
rho= corr(r1(:),r2(:));
  댓글 수: 2
Nirajan Khatri
Nirajan Khatri 2020년 9월 24일
is it
rho= corr(y1(:),y2(:));
or
rho= corr(r1(:),r2(:));
Ameer Hamza
Ameer Hamza 2020년 9월 24일
Both are correct syntax. You need to decide which one to use for this problem.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by