User`s guide
A Simple Example — The Sierpinski Gasket
3-3
The curve can be graphed in many ways. Sierpinski's method is
• Start with a triangle and from it remove a triangle that is one-half the height
of the original and inverted. This leaves three triangles.
• From each of the remaining three triangles, remove a triangle that is
one-fourth the height of these new triangles and inverted. This leaves nine
triangles.
• The process continues and at infinity the surface area becomes zero and the
length of the curve is infinite.
To achieve a reasonable approximation of the Sierpinski Gasket, set the
number of points to 50,000. To invoke the M-file and compute the coordinates,
you can use
x = gasket(50000);
To display the figure, you can use
imagesc(x); colormap([1 1 1;0 0 0]);
axis equal tight
Compiling the M-File into a MEX-File
To create a MEX-file from this M-file, enter the mcc command at the MATLAB
interpreter prompt.
mcc -x gasket
This mcc command generates
• A file named
gasket.c containing MEX-file C source code.
• A file named
gasket.h containing the public information.
• A file named
gasket_mex.c containing the MEX-function interface (MEX
wrapper).
• A MEX-file named
gasket.mex. (The actual filename extension of the
executable MEX-file varies depending on your platform, e.g., on the PC the
file is named
gasket.dll.)
mcc automatically invokes mex to create gasket.mex from gasket.c and
gasket_mex.c. The mex utility encapsulates the appropriate C compiler and
linker options for your system.