Discussion:
corr2.m in MATLAB and Octave
ykrsch k
2010-08-20 19:08:38 UTC
Permalink
Hi, I'm new to the Octave but trying hard to migrate on it. I found that
I've got a different result when I'm running "corr2" function in MATLAB and
Octave.

I use the same size of two matrices and then used as:

R = corr2(matrixA, matrixB);

in MATLAB R is one correlation coefficient just as:
http://www.mathworks.com/access/helpdesk/help/toolbox/images/corr2.html.

However, when I run the same script in Octave, the answer turns out to be a
matrix. For example is I used 5000x600 matrix, the R is 600x600.

I'd very much appreciate if anyone can explain to me why this is happening.

Thanks in advance,
Carnë Draug
2010-08-25 14:31:20 UTC
Permalink
Hi

I can confirm that. I don't know if the octave's corr2 is supposed to
work differently than matlab's corr2 (although the description in the
link you gave is similar to the one in corr2 help text). The following
code gives a matrix, not a scalar

a = rand(5);
b = rand(5);
r = corr2(a,b)
Post by ykrsch k
Hi, I'm new to the Octave but trying hard to migrate on it. I found that
I've got a different result when I'm running "corr2" function in MATLAB and
Octave.
R = corr2(matrixA, matrixB);
in MATLAB R is one correlation coefficient just
as:http://www.mathworks.com/access/helpdesk/help/toolbox/images/corr2.html.
However, when I run the same script in Octave, the answer turns out to be a
matrix. For example is I used 5000x600 matrix, the R is 600x600.
I'd very much appreciate if anyone can explain to me why this is happening.
Thanks in advance,
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Octave-dev mailing list
https://lists.sourceforge.net/lists/listinfo/octave-dev
Marco Atzeri
2010-08-25 15:36:15 UTC
Permalink
Post by Carnë Draug
Hi
I can confirm that. I don't know if the octave's corr2 is
supposed to
work differently than matlab's corr2 (although the
description in the
link you gave is similar to the one in corr2 help text).
The following
code gives a matrix, not a scalar
a = rand(5);
b = rand(5);
r = corr2(a,b)
Post by ykrsch k
Hi, I'm new to the Octave but trying hard to migrate
on it. I found that
Post by ykrsch k
I've got a different result when I'm running "corr2"
function in MATLAB and
Post by ykrsch k
Octave.
R = corr2(matrixA, matrixB);
in MATLAB R is one correlation coefficient just
as:http://www.mathworks.com/access/helpdesk/help/toolbox/images/corr2.html.
However, when I run the same script in Octave, the
answer turns out to be a
Post by ykrsch k
matrix. For example is I used 5000x600 matrix, the R
is 600x600.
Post by ykrsch k
I'd very much appreciate if anyone can explain to me
why this is happening.
Post by ykrsch k
Thanks in advance,
I guess that to replicate Matlab

you need to call corr2(a(:),b(:))

as for cov
http://octave.sourceforge.net/nan/function/cov.html

Marco
Carnë Draug
2010-08-25 17:57:35 UTC
Permalink
Post by Marco Atzeri
I guess that to replicate Matlab
you need to call corr2(a(:),b(:))
as for cov
http://octave.sourceforge.net/nan/function/cov.html
Marco
Can't this be adjusted in the function? By looking at the code of
corr2, swapping

cov (I, J) / (std2(I)*std2(J));

by

cov (I(:), J(:)) / (std2(I)*std2(J));

would suffice to have compatibility. Or would this break something?

Carnë Draug
Søren Hauberg
2010-10-20 20:08:28 UTC
Permalink
Post by Carnë Draug
Post by Marco Atzeri
I guess that to replicate Matlab
you need to call corr2(a(:),b(:))
as for cov
http://octave.sourceforge.net/nan/function/cov.html
Marco
Can't this be adjusted in the function? By looking at the code of
corr2, swapping
cov (I, J) / (std2(I)*std2(J));
by
cov (I(:), J(:)) / (std2(I)*std2(J));
would suffice to have compatibility. Or would this break something?
Sorry about the ridiculously late reply.

This change does indeed seem to be compatible with Matlab, so I've made
it.

Thanks
Søren

Loading...