%gaussian2d.m %Create a 3D printable 2D Plot of Gaussian curve in standard deviation %segments %Steven Sahyun October 27, 2015 clear; clf(); center = 0; %The x values here are setting the depth of the print. xplotwidth = 20; xmin = center-xplotwidth; xmax = center+xplotwidth; xstep = (xmax-xmin)/100; %100 data points x = xmin:xstep:xmax; %Change these y values to affect the shape of the graph. You can change the %begining and end points for "plotting" by changing ymin and ymax. ystddev = 10; yplotwidth = 40; ymin = center-4*ystddev; %Change the start point in terms of # of standard deviations ymax = center+4*ystddev; %Change the end point in terms of # of standard deviations ystep = (ymax-ymin)/100; %100 data points y = ymin:ystep:ymax; xstddev = 10; %xwidth = sqrt(2)*xstddev; xwidth = 100; %This is a large value to produce a 2D plot. %ywidth is the y standard devivation * sqrt (2) since the denominator in the % exponential is 2*stddev^2 ywidth = sqrt(2)*ystddev; %ywidth = 1; zscale = 500/(xstddev*sqrt(2*pi)); %500 seems to be a good amplitude based on width of 40. z = zscale*exp(-((y-center)./ywidth).^2)'*exp(-((x-center)./xwidth).^2); %Provide a border with height of 0 that is 10 columns wide. %get size of z, m = rows, n=columns [m, n] = size(z); z(:,1:10)=0; z(:,n-10:n)=0; %Plot the surface surf(x,y,z); axis([center-xplotwidth, center+xplotwidth, center-yplotwidth, center+yplotwidth, 0, zscale]) %Convert to a 3D printable file; You need to have stlwrite.m and surf2solid.m by %Sven Holcombe in the same directory as this file. %See: http://jmumakerlab.blogspot.com/2013/11/exporting-stl-from-matlab.html % http://www.mathworks.com/matlabcentral/fileexchange/42876-surf2solid-make-a-solid-volume-from-a-surface-for-3d-printing % http://www.mathworks.com/matlabcentral/fileexchange/20922-stlwrite-filename--varargin- %minz = 0; %maxz = zscale; %c=255*((z+minz)/maxz); GaussianSurface = surf2solid(x, y, z, 'ELEVATION', -0.5); %Can change Elevation for a thicker base. stlwrite('GaussianSurfacestl.stl',GaussianSurface)