I want to calculate covariance of 400 50 X 50 matrices using loop so when I tried..
for i=t-9:t+59
for j=r-9:r+59
a(:,:,p)=vidFrames2(i:(i+49),j:(j+49));
b(:,:,p)=cov3d(double(a));
p=p+1;
end
end
this code I got error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" but when i want to remove this error by squeeze function in this code,
b(p,:)=cov3d(squeeze(double(a)));
I got "Subscripted assignment dimension mismatch."
how can I calculate covariance of 3d matrix....the cov3d
function is-
function xy = cov3d(x)
[m,n,r] = size(x);
if m==1
x=zeros(n,n,r,class(x));
else
xc=bsxfun(@minus,x,sum(x,1)/m);
for i=1:r
xci=xc(:,:,i);
xy(:,:,i)=xci'*xci;
end
xy=xy/(m-1);
end actually i wanted 400 number of covariance matrices stored in a variable.after this change i only get one covariance matrix.actually i am working on a frame where i am storing the initial coordinate values in i and j of a 50 X 50 matrix. then i want to get the pixel values of the 10 X 10 neighbourhood in the form of 50 X 50 matix. that means if i entered the initial coordinate as (100,100), then i want to get pixel values stored within region (91,91)(91,141)(141,91)(141,141).then store the covariance value of this matix. then again it will find the pixel values of the region (92,91),(142,91)(92,141),(142,141)and so on and covers the whole area..so if i cover the whole area then i think i will get total 400 matrices.and i want to store the covariance value of all the regions,.. today i changed the upper limit of the for loops to i=t-9:t+60 and j=r-9:r+60 but i did not get 400 covariance matrices