MATLAB: Need repmat help

repmat

Hello,
I have a 4D array with two for loops that is very slow. I know repmat is a good tool to speed things up but I am not very good at using it yet. Is there a way to use repmat to replace the follow set of for loops:
%th_diff3_1 has the following dimensions (621,1405,12,116)
for a = 1:621
for b = 1:1405
x = sum(th_diff3_1(a,b,:,:));
x = sum(x(1,1,:,:));
percent3_1(a,b) = (x/1390) * 100;
end
end
Please help me understand repmat!
Thanks,
Dan

Best Answer

It's not about repmat. I think you can do this:
x=sum(th_diff3_1,4);
x=sum(x,3);
percent3_1=(x/1390) * 100