Array of Gaussians limited to small size (hangs indefinitely). How can this be avoided?

1 view (last 30 days)
Hi everyone,
I'm new to Matlab. I have created an array of Gaussians for a model. It works very well when it is square. However when I have a different number of gaussians in x than in y, I run into trouble.
x = linspace(-(handles.metricdata.space * handles.metricdata.sizex), (handles.metricdata.space * handles.metricdata.sizex), 1000);
y = linspace(-(handles.metricdata.space * handles.metricdata.sizey), (handles.metricdata.space * handles.metricdata.sizex), 1000);
[X,Y] = meshgrid(x,y);
gx = -(handles.metricdata.sizex -1) * 0.5:(handles.metricdata.sizex-1)* 0.5;
gy = -(handles.metricdata.sizey -1) * 0.5:(handles.metricdata.sizey-1)* 0.5;
[x_g,y_g] = meshgrid(gx,gy);
mu = [x_g(:) , y_g(:)];
z = zeros(size(handles.metricdata.sizex));
for i = 1:size(mu,1)
z = z + samp * exp(-((X-handles.metricdata.space*mu(i,1)).^2+(Y-handles.metricdata.space*mu(i,2)).^2)/( 2*(sigma).^2));
end
So this is my code in the version I use for a GUI. For x values of 8 or higher it does not work. If I remove y input and set x = y then it works. If I use small values (e.g. 3*2) then it works 5 or 6 times then hangs after that and I have to restart Matlab.
What I really want is something of the order 50*25 or so.
I have checked memory and that seems fine. Also, even for 7*7 it takes max 4 seconds to run.
Thanks for any help or insight that you can provide.
PM

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!