Apple Xcode, implemented in the Objective-C language, is used to develop applications using the Cocoa framework, the native object-oriented API for the Mac OS X operating system.
This article details how to deploy a graphical MATLAB® application with Objective C and Cocoa, and then deploy it using MATLAB Compiler™.
You can find example Apple Xcode, header, and project files in
To run this example, you should have prior experience with the Apple Xcode development environment and the Cocoa framework.
Build the shared library with MATLAB
Compiler using either the Library Compiler or
Compile application code against the library’s header file and link the
application against the component library and
libmwmclmcrrt. For information about
libmwmclmcrrt and MATLAB Runtime, see Problems Setting MATLAB Runtime Paths (MATLAB Compiler).
In your Apple Xcode project:
Specify target settings in
Specify directories containing the library header.
Specify the path
establishes the install route using a relative
LIBRARY_SEARCH_PATHS to any directories
containing the shared library, as well as to the path
In this example, you deploy the graphical Sierpinski function (
sierpinski.m, located at
function [x, y] = sierpinski(iterations, draw) % SIERPINSKI Calculate (optionally draw) the points % in Sierpinski's triangle % Copyright 2004 The MathWorks, Inc. % Three points defining a nice wide triangle points = [0.5 0.9 ; 0.1 0.1 ; 0.9 0.1]; % Select an initial point current = rand(1, 2); % Create a figure window if (draw == true) f = figure; hold on; end % Pre-allocate space for the results, to improve performance x = zeros(1,iterations); y = zeros(1,iterations); % Iterate for i = 1:iterations % Select point at random index = floor(rand * 3) + 1; % Calculate midpoint between current point and random point current(1) = (current(1) + points(index, 1)) / 2; current(2) = (current(2) + points(index, 2)) / 2; % Plot that point if draw, line(current(1),current(2));, end x(i) = current(1); y(i) = current(2); end if (draw) drawnow; end
Using the Mac Finder, locate the Apple Xcode project
Copy files to a working directory to run this example, if needed.
sierpinski.xcodeproj. The development environment
In the Groups and Files pane, select Targets.
Click Build and Run. The make file runs that launches
Run the Sierpinski application from the build output directory. The following GUI appears:
MATLAB Sierpinski Function Implemented in the Mac Cocoa Environment
In the Iterations field, enter an integer such as
Click Draw Triangle. The following figure appears: