Programmatically package a MATLAB toolbox - matlab

The toolbox packaging functionality new in R2014b looks pretty nice.
However, you seem to be able to package a toolbox only via the toolbox-packaging GUI.
I'd like to be able to create a .prj file interactively using the GUI, and then programmatically package the toolbox using this .prj file, incorporating this programmatic step into a wider build process (which also includes checking things out, running a unit-test suite etc).
Does anyone know of a way to do this (documented or not, supported or not)?
I took a look at MATLAB\R2014b\toolbox\matlab\toolbox_packaging\+matlab\+tbxpkg\+internal\create.m - this seems to mostly do the job, but it requires that the .prj file is in a specific location relative to the toolbox folder.
I was hoping for something similar to the app-building classes such as matlab.apputil.

As of R2016a there is new functionality to programmatically package a toolbox.

Related

Send commands to an existing MATLAB IDE command window

After we open a MATLAB IDE, are we still able to write to its command window from another process?
In Windows, we could use MATLAB Engine API to attach to an existing MATLAB, while this does not work in Linux/Mac.
Do we have any solutions in Linux?
If you want to connect from a separate java process, consider using MatlabControl. It allows you to easily launch new Matlab instance from java process and then communicate with it though JMI, i.e. java-to-matlab interface that is shipped with each Matlab release.
Is it also possible to connect to existing Matlab instance, but you will need to modify MatlabControl code to do that, and you will need to manually execute some command from within the Matlab instance you wish to connect to.
There is a nice series of articles on MatlabControl / JMI on Undocumented Matlab.
As of 2016b, there is also an official MATLAB Engine API for Java.

Integrating Matlab with C++

I need to localize facial landmarks as a part of my research project and planning to use Supervised Descent Method (SDM) for that. Both the C++ and Matlab versions are available at the following site and when I contacted them they said C++ version is not going to be available until they secure it. So, I had no other option and had to opt for Matlab version.
http://www.humansensing.cs.cmu.edu/intraface/download_functions_matlab.html
The problem is that My project is in C++ and OpenCV. I wonder whether there is a way to access Matlab version of SDM in Visual C++ . I mean, is there an integration mechanism available for that ?
And, the next issue is when executing the "Facial Feature Detection" code available at the above site I get the following error.
I executed it as given below.
[detected_points] = xx_track_detect(Model,[],image,[],options);
and, it says "undefined function or variable named 'model' "
anyone have a solution to this ?
It seems like you need to use Matlab engine to be able to execute Matlab commands from C++. The engine interface allows you to do just so.
Regarding the model variable - it is probably a representation of the learned model for facial landmarks, it should be supplied with the packge or you need to tune it by yourself. Without additional information I suggest you contact the publishers of the package for more information.

How can I package a MATLAB application that utilises toolboxes?

I want to package up an application in MATLAB for another team to use. They will have an appropriate version of MATLAB to run this application, but they might not necessarily have licenses for all the toolboxes used by the application.
Is there a way to "bundle" the toolboxes into the application so that they do not require expensive licenses to run it?
If not, is it possible to create a stand-alone/license independent MATLAB application a different way?
EDIT: Some of these applications might feature GUIs as well as command line interfaces.
To generate code that can be run by MATLAB, you need the MATLAB Coder. The codegen command will generate the executables that can be run in MATLAB. Loren of MathWorks has a nice blog post on the product.
Here is an example of how to use codegen to create a MEX function from MATLAB code.
One big caveat is that with MATLAB Coder, the complete functionality of MATLAB is not yet available for compilation. This is because the generated binaries do not require the MATLAB Compiler Runtime (MCR), which is essentially a headless MATLAB virtual machine. Instead MATLAB Coder generates C code that is truly standalone, but the code generation is somewhat limited as a result. Here is a description of the subset of functionality, and here are complete lists of functions supported. Most toolkit functions appear to be supported according to the categorical list.
If the required functions are not supported, then it will be necessary to use the Compiler to generate standalone libraries and roll your own MEX interface to those libraries, as MrAzzaman indicated. Another possibilities is to use the loadlibrary function to directly load the Compiler-generate libraries, although I have never tried this last option. If you can't successfully interface with these libraries back in MATLAB, the MATLAB compiler can of course be used to generate a standalone executable. The deploytool simplifies the process of packaging the code and its dependencies.
The MATLAB Compiler sounds like exactly what you need. Unfortunately, it is a separate Toolbox which you would have to purchase.
EDIT: I should note that this will compile your MATLAB code into an application/library, not MATLAB code. The other team would still be able to use it with MATLAB, I believe, but I don't think they would be able to see the code itself.

Creating a standalone app from Matlab code

I have some Matlab code and a GUI for it and I want to make a standalone .exe so that it can be used on computers that don't have Matlab installed.
I know about the Matlab compiler and how to use it, but that creates an .exe that only works if the user has the MATLAB Compiler Run-Time (MCR) installed.
What I'm interested in, is if there are any ways to create a standalone .exe that still uses the Matlab code but does not depend on the MCR. I want it to just run when you click it without needing anything else installed.
I know C can make use of Matlab, is there any way to use the code with C? How about any open source Matlab alternatives that can it?
As a last resort, if I were to rewrite the Matlab code in another language, what language would you recommend? I was thinking C or Python.
Thanks.
It's been a while since I looked at the MATLAB compiler but if I remember correctly it used to be able to generate C/C++ code rather than going all-out and generating an executable. The hangup was always in which toolboxes your code used and whether the compiler supported them or not. Any chance you could install the MATLAB application on a server and have a desktop client phone in for results?
As far as other languages go, I'd check out NumPy and SciPy in combination with matplotlib (matplotlib.sf.net). I'm working with a MATLAB developer right now and so far he's pretty pleased with the experience.
The MCR is required, but there's a trick: it doesn't actually have to be installed, just available on the PATH. Running MCR stuff doesn't require any registry entries or anything else special from the installation process. You just need the MCR files readable and the DLLs locatable by the normal lookup mechanism, which includes checking the PATH at the time of program launch.
For example, I've run compiled Matlab apps using an MCR that's "installed" on a network drive. You run the MCR installer on one machine and have it install to network drive X:\Matlab\MCR\R2010b-win32 instead of the usual C:\Program Files location. Then have your program be launched through a wrapper script that adds X:\Matlab\MCR\R2010b-win32\bin\win32 to the PATH before calling your actual .exe file, and it'll run on any other machine that sees the same drive, even if the MCR installer hasn't been run on them. (Eventually we stopped because loading the MCR from the network is a performance hit.)
You could use this trick to bundle the MCR with your application. Stick the whole MCR installation (the dir tree resulting from installation, not the installer program itself) in a subdirectory of your application's directory tree, and have the entry point to your app be a .bat file or other wrapper script that sticks that MCR dir on the PATH before running your MCR-dependent .exe file.
Of course, check with your legal folks to make sure this doesn't violate your licensing terms.
MathWorks recently introduced a new product MATLAB Coder. It is capable of generating C\C++ code from your MATLAB code (generates source code not executables). The generated code is portable and does not depend on the MCR, though it only supports a subset of core MATLAB language features.
I have researched a bit, and I am afraid that your only option is either using the MCR, or converting your code into another language. It makes sense that MathWorks would want you to use only their compiler in order to create .exe files.
Consider another language only if you are already familiar with them, and/or you have enough time for what you are trying to accomplish. Furthermore, if you are using functions in Matlab that you didn't write, then you will have to write those also, which may be very hard/impossible.
If none of the above is a problem, then what language you should use is really up to you. You are not just limited to C and Python. Matlab, im my opinion, is very much like other common languages, at least in terms of syntax. You will have to do some learning either way, so I would suggest that you either go with a language you know, or pick a language for which finding help is easy. C# and Java are two of the more 'famous' languages.
The Matlab 'compiler' is not a compiler. It translates Matlab m-code into C++ code and then sends that to an actual compiler like the one in Visual Studio, etc. The code it makes is not really human-readable.
To make a standalone app, install the following toolboxes (at whatever price you paid):
MATLAB Builder JA, MATLAB Builder NE, MATLAB Compiler
Set up the Matlab compiler by pointing it to the actual compiler on your drive (i.e. mbuild -setup).
Select a compiler:
[1] Microsoft Visual C++ 2008 SP1 in C:\Program Files (x86)\Microsoft Visual Studio 9.0
Then use the (i.e. type deploytool) to make the main and to define various helper functions etc. Sect windows console or standalone. Then click build. It will make the exe-file for you. You can also compile to DLL, etc as needed.
Newer versions of the 'compiler' support compiling of eval, all toolboxes that are licensed, and it supports import of java classes that will allow you to use for example, a DOM for xml-file parsing etc.
To use the resulting exe-file on a computer that does not have Matlab installed on it, you need to obtain the Matlab MCR and install it. The MCR must match exactly the version of Matlab you used to make the compiled code.
Regards,
Ivan

Graphically laying out wx app

Being really new to wx, I'm wondering if there is an IDE (especially for Linux) which would help me lay out a frame or dialog or whatever just to help me see what I'm doing. That means also creating the code for those changes.
I remember way back when using resource compilers for OS/2 and Windows that produced binaries that would then create the window, and was hoping for something similar (though obviously not binary if wx doesn't support that).
I use wxFormBuilder. It is written in wxWidgets, so it works on Linux quite well. It can generate C++ code or XRC files. Make sure you understand its philosophy, and use it like this:
generate C++ code for the GUI
don't edit the code wxFormBuilder generated, but create new files
in new files, derive new classes from the classes it generated
implement event handlers in you own class (wxFB creates virtual function for each event handler you wish to use)
I usually name the wxFormBuilder generated classes/files like, for example, MainFrameGUI, and one with implementation (derived one in which I write all my code) would be just MainFrame. This enables you to change the visual layout and regenerate C++ files from wxFB at any time without overwriting your code.
DialogBlocks works quite well for me, although sometimes you need to edit the code to fix errors manually. It has a property editor that seems advanced enough.
Just another options is wxGlade. It does not have the that much features as the others mentioned seem to have, but it works just good enough for me to not daring to switch.
I use Code::Blocks IDE from http://www.codeblocks.org which has
- built-in GUI editor
- Cross compilable, so you can use it under Linux, OSX and Windows.
But I still use wxFormBuilder with it instead of built-in wxSmith editor. But they are compatible with internal wxSmith.
For windows you've got "wx-devcpp" which is Blodsheed Dev C++ with some addons providing what you looking for
Here is project page
http://wxdsgn.sourceforge.net/