How to call MATLAB code from Objective-C

I plan to write my algorithmic codes in Matlab. And I need to convert the .m files to a format in which Objective-C can access. When I try to execute mcc, the following error appeared.

The -t switch is no longer supported; the Compiler no longer generates C/C++ source code for M-functions (it generates wrapper functions instead, see the documenation for -W). 

If mcc does not generate C source codes, how can I create wrappers? and I need to copy both the m file and the shell so that everything works ?. And will these wrappers work in iOS?

+4
source share
2 answers

The MATLAB compiler does not convert MATLAB code to C code and has not done so for a long time.

Instead, it archives and encrypts your MATLAB code and creates a shell (which can be executable, a library, or, if you have access to any of the Builder products, a .NET assembly, a Java.jar file, or an Excel add-in). This shell unarchives and decrypts your MATLAB code and runs it against the Runtime of the MATLAB compiler, which should be included in your application (but free).

You cannot run MCR on iOS - its size is too large. If you are targeting another platform using Objective-C, you can create a library using the MATLAB Compiler and call it from Objective-C.

MATLAB Coder (not like MATLAB Compiler) can convert a subset of MATLAB into C code. If you are targeting iOS, this will be one of the approaches, or you can alternatively run your MATLAB code remotely and your application will access it via the Internet.

+3
source

I am a little confused by what you wrote, so I may not answer your real question:

The Matlab documentation contains clear instructions for using the Matlab mechanism from C programs. Since Objective-C is just C with buttons, I see no reason why you shouldn't call the engine from Objective-C. Everything that the Matlab engine sees when it is running is a valid call, it does not know what language the calling program is written in.

I think mcc does not matter for your use; you need an Objective-C compiler on your Mac. Matlab documentation assumes that a compiler included in Xcode prior to version 4.1 is suitable for Matlab-enabled applications. In my experience, it may take a little work with the compiler options to make a more recent compiler with your Matlab installation, but nothing more.

If you plan on using the Objective-C Matlab call, you might not want to start by writing M files for your algorithmic kernel. Actually, you probably will, but the Matlab mechanism doesnโ€™t really run M files, it executes the commands sent to it by an external program, for example, your Objective-C program. Your development path can be (1) write an M file to implement the algorithm, then (2) write an Objective-C program that calls the Matlab mechanism at critical stages when the Matlab function is required. You can write your application to make the engine run the M file (I think), but this does not match my experience.

While you can use Matlab to run the compiler to create your programs, in this case you are probably better off using Xcode (or your preferred Mac IDE) to create your programs, making sure that the correct connections are made with the Matlab Engine . Again, the documentation explains what you need to do.

No wrappers. No M files. And good luck getting the Matlab engine running on iOS!

+3
source

Source: https://habr.com/ru/post/1397992/


All Articles