Vectorization instead of for loop
Show older comments
Hi.
I have an image with about 5000 objects on that I have the centroid (xf,yf) locations for. My aim is to take each one and perform a Gaussian Fit to. I currently use a for - loop and want to see if vectorization speeds it up, but I can't figure out how to.
heres my for - loop code:
l=numel(xf)
delta=5; %half width span of data to perform fit to
for indx=1:l
xrange=xf(indx)-delta:xf(indx)+delta; % create x range
ydata=B(yf(indx),xrange)'; %B=Original Image, so y is the intensity at the xrange positions
xdata=(1:2*delta+1)';
%Now do Gaussian fit
[a(indx),b(indx),c(indx),d(indx),xpeak(indx),ypeak(indx),r2(indx)]=myGaussianFit(double(xdata),double(ydata), b0,c0);
fwhm(indx) = c(indx) * sqrt(log(256));
fwhmSUM=fwhmSUM+fwhm(indx);
data(indx,1)=xf(indx);
data(indx,2)=yf(indx);
data(indx,3)=fwhm(indx);
data(indx,4)=r2(indx);
data(indx,5)=a(indx);
data(indx,6)=b(indx);
data(indx,7)=d(indx);
data(indx,8)=xpeak(indx);
data(indx,9)=ypeak(indx);
end
Thanks Jason
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!