1

I have a matrix 64x64x32x90 which stands for pixels at x,y,z, at time t. I have a reference signal 1x90 which stands for the behavior I expect for a pixel at some point (x,y,z). I am constructing a new image of the correlation between each pixel versus my reference.

load('DATA.mat');
ON = ones(1,10);
OFF = zeros(1,10);
taskRef = [OFF ON OFF ON OFF ON OFF ON OFF];

corrImage = zeros(64,64,36);
for i=1:64,
    for j=1:63,
        for k=1:36
            signal = squeeze(DATA(i,j,k,:));
            coef = corrcoef(signal',taskRef);
            corrImage(i,j,k) = coef(2);
        end
    end
end

My process is too slow. Is there a way to get rid of my loops or adjust the code to have a better runtime?

Shabbir Hussain
  • 2,600
  • 2
  • 17
  • 25

1 Answers1

1

Reshape your data so that its first three dimensions are collapsed into one (so now there are 64*64*32 rows and 90 columns).

Then use pdist2 (with 'correlation' option) to compute the correlation of each row with the expected pattern.

Finally, reshape result into the desired shape.

DATA2 = reshape(DATA, [],90);
corrImage = 1 - pdist2(DATA2, taskRef, 'correlation');
corrImage = reshape(corrImage, 64,64,32);
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147