문제

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