Error using corrcoef. x and y must have the same number of elements....?

13 次查看(过去 30 天)
Hi everyone!
Running some fMRI stuff and we are having some trouble trying to figure out what Error using corrcoef X and Y must be have the same number of elements
for r=1:roiN
fcmap=zeros(1,numpix); %1-by-#num voxels in 3D volume
seedts=load([roiList{r},'_','residvol_ts.txt']);
for pix=1:size(fcmap,2) %1 to #num voxels in 3D volume
tmp=corrcoef(seedts,func(:,pix)); %calc correlation bewteen seed timeseries and timeseries of that voxel; tmp=2x2 symmetric corr table
pixr=tmp(1,2);
fcmap(pix)=pixr; %fill voxel with correlation coefficient
if doFisherZ
fcmap(pix)=(.5*log((1+pixr)/(1-pixr)));
else
end
end
Thanks for your help :)
  1 个评论
Mathieu NOE
Mathieu NOE 2023-2-28
yeap
read the doc
% this work
A = randn(10,1);
B = randn(10,1);
R = corrcoef(A,B)
R = 2×2
1.0000 0.3131 0.3131 1.0000
% this doesn't work
A = randn(10,1);
B = randn(12,1);
R = corrcoef(A,B)
Error using corrcoef
X and Y must have the same number of elements.

请先登录,再进行评论。

回答(1 个)

Dinesh
Dinesh 2023-3-27
Hi Ryu!
Here in this line of code
tmp=corrcoef(seedts,func(:,pix));
The time series seed array and time series voxel are not having same number of elements and without same number of elements we cannot calculate correlation coefficent. Despite how they are shaped to calculate corrcoeff we need to have same number of elements.
For more Details on how correlation coefficient is calculated and it's internal mathematics please refer the following MATLAB Documentation

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by