I tried turning this:

for r=1:fsize
     for c=1:fsize
         mask(r,c) = exp(-(((r-centre)^2+(c-centre)^2)/2*(sigma^2)));
     end
 end

into

mask(1:fsize,1:fsize) = exp(-(((1-centre:fsize-centre).^2.+(1-centre:fsize-centre).^2)./2.*(sigma.^2)));

but I now get the error "Subscripted assignment dimension mismatch".

My understanding is that this has something to do with the indexing in the two arrays not being matched, but that doesn't seem to be the case here?

有帮助吗?

解决方案

use meshgrid for that,

[r c]=meshgrid(1:fsize);
mask = exp(-(((r-centre).^2+(c-centre).^2)/2*(sigma^2)));   

this assumes that centre and sigma are scalars.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top