Path: news.mathworks.com!not-for-mail From: Peter Perkins <Peter.Remove.Perkins.This@mathworks.com> Newsgroups: comp.soft-sys.matlab Subject: Re: Corrcoef(A,B) when Var(A)=0 Date: Fri, 04 May 2012 13:53:59 -0400 Organization: The MathWorks, Inc. Lines: 39 Message-ID: <jo153n$gi5$1@newscl01ah.mathworks.com> References: <jo0uls$gql$1@newscl01ah.mathworks.com> NNTP-Posting-Host: ah-pperkins.dhcp.mathworks.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: newscl01ah.mathworks.com 1336154039 16965 172.31.57.194 (4 May 2012 17:53:59 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 4 May 2012 17:53:59 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: <jo0uls$gql$1@newscl01ah.mathworks.com> Xref: news.mathworks.com comp.soft-sys.matlab:766852 Laurie, consider these two vectors: x = [1 2 3 4 5] y0 = [0 0 0 0 0] If you plug those into the computational definition of the linear correlation corr(x,y0), you will find that it's 0/0, which in floating point is represented as NaN. So instead consider y = [1 2 3 4 5] Since computing corr(x,y0) directly ended up as 0/0, you might think to compute it as the limit of corr(x,alpha*y) as alpha goes to zero. Now corr(x,alpha*y) is 1 for alpha > 0, so the limit from that side is 1, but for alpha < 1 the limit is -1. And if you approach y0 some other way (using y1 = [1 2 3 2 1], say), you can make the limit anything in [-1,1]. So the limit is path dependent. And since there's no way for the corrcoef function to "know" which of the infinite possibilities you want, the result is NaN, meaning, "it might be any one of many numbers." Hope this helps. On 5/4/2012 12:04 PM, laurie wrote: > Hi, > > I would like to get the correlations between one vector B and another, > constant, vector A. > > So the constant vector A is so that Var(A)=0 and corrcoef gives either > NaNs or 0 (sometimes, but I don't know why ?). > > Is there a workaround this ? I don't see why a correlation coefficient > would be impossible mathematically when one of the two variance is zero ? > > For example can I add a little noise without alterring my data to much ? > > Thank you very much