Numerical errors in corrcoef
Mostrar comentarios más antiguos
I noticed that the output from corrcoef for a large matrix has some very tiny but non-zero numerical difference from the output I get by literally doing "for loops" to loop through all the columns myself. Is this a known issue? What would cause such difference? Here is a quick code I used to demonstrate this:
function matlab_corrcoef_issue
close all
A = randn(1000, 100);
R = corrcoef(A);
S = corrcoef_slow(A);
D = R-S;
plot(D(:));
return
function out = corrcoef_slow(M)
num_col = size(M,2);
out = zeros(num_col, num_col);
% This is to literally loop through
for i = 1:num_col
for j = i:num_col
r = corrcoef(M(:,i), M(:,j));
r = r(1,2);
out(i,j) = r;
out(j,i) = r;
end
end
return
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!