0

Ok, I have the following problem in Matlab and it has been bugging me for quite some time now: Lets say I have 2 vectors (x and y) and I wish to get the correlation between them. I can call the function corrcoef which returns a matrix, but I am only interested in the element at position (1,2) since the other positions are duplicates or simply the number 1 along the diagonal.

I can do this with c = corrcoef(x,y); but this gives a whole matrix... How can I get the correlation of x and y in one line of code? Now I do: C = corrcoef(x,y); c = C(1,2); but I want to do this in one line...

Héctor van den Boorn
  • 1,218
  • 13
  • 32
  • Can you explain what the reason is? – NKN Dec 06 '15 at 21:36
  • 1
    Why don't you limit your input `c = corrcoef(x(...),y(...));` ? – Robert Seifert Dec 06 '15 at 21:37
  • 1
    If you *really* **really** ***really*** don't like the extra temp variable hanging around in your workspace, you can do `C = corrcoef(x,y); C = C(1,2);` – beaker Dec 06 '15 at 21:52
  • [SUBSREF](http://www.mathworks.com/help/matlab/ref/subsref.html) but it's arguable if you'll actually get any performance gain. It will certainly be less readable ... – brown.2179 Dec 07 '15 at 01:33

0 Answers0