How do I correlate columns
Show older comments
I have 2400 x 1015 matrix. I would like to correlate column 1 with column 926. I would then like to correlate column 1 with 927 and so on until I correlate column 1 with column 1015.
I would then like to print the result of each correlation in row 1, in a new file.
Thanks
1 Comment
Jonathan Campelli
on 14 Apr 2015
I've made a program that's computing each correlation by the formula, which is returning totally different results from my previous code. Just updating you that I'll post the correct code within the next couple hours, in case you have need of it still. "corrcoeff" was yielding different results than those you asked for. Coming soon...
Jonathan Campelli
Accepted Answer
More Answers (2)
Chad Greene
on 13 Apr 2015
How's this?
m = rand(2400,1015);
c = corrcoef(m(:,[1 926:1015]));
imagesc(c)
cb = colorbar;
ylabel(cb,'correlation coefficient')
4 Comments
Kris
on 13 Apr 2015
Jonathan Campelli
on 13 Apr 2015
Hello, Kris,
What operation are intending to indicate by the word "correlate"? I may be unfamiliar with the application, and thereby having trouble understanding.
Best,
Jonathan Campelli
Kris
on 13 Apr 2015
Jonathan Campelli
on 13 Apr 2015
Alright, cooking up some code...
Chad Greene
on 13 Apr 2015
The rand function was only to generate random data to play with.
I don't see how you'll get a 925 x 90 correlation matrix. Here I'll make up some data, but set column 1 to sine wave, then columns 926 to the end will have an increasingly high sine wave to random noise ratio. So correlation increases from columns 926 to 1015, as is evident in the top row of subplot 3:
% Some random data:
m = rand(2400,1015);
% The first column is sine function:
m(:,1) = sind(1:2400);
% Force correlation to come increasingly positive
% from cols 926 to 1015,
mag = 0;
for k = 926:1015
m(:,k) = m(:,k) + mag*sind(1:2400)';
mag = mag+.01;
end
subplot(131)
imagesc(m)
title 'full dataset'
subplot(132)
imagesc(corrcoef(m))
title 'correlation all data'
caxis([-1 1])
subplot(133)
c = corrcoef(m(:,[1 926:1015]));
imagesc(c)
title 'correlation of cols 1, 926:1015'
caxis([-1 1])
rgbmap('red','white','blue')

Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!