0
votes

I have 2 m x n matrices and would like to calculate canonical correlations for segments within a given window length. For example, if my window length is 100, I'd like to have the correlation coefficients for

canoncorr(X(1:100,:),Y(1:100,:))
canoncorr(X(101:200,:),Y(101:200,:))
canoncorr(X(201:300,:),Y(201:300,:))
...

and so on all accumulated into one matrix. I am only interested in the correlation coefficient r.

I am trying the following:

win=100;
r=[];
for i=1:win:size(X,1)-win-2
    [A,B,r(i,:)] = canoncorr(X(i:i+win,:),Y(i:i+win,:));
end

However, my resulting matrix does not only save the values from row 1, 101, 201 etc. but also fills the rows between 1 and 101 and so on with zeroes.

If I try

 [A,B,r(i:i+win,:)] = canoncorr(X(i:i+win,:),Y(i:i+win,:));

then subscripted assignment dimensions mismatch.

What am I doing wrong?

1

1 Answers

0
votes

i goes from 1, 101, 201, ...

so, please check for 101th row and see if they are zero.

you can also spy(r) to see matrix elements.