Distribute matlab functions without source - matlab

I have written a set of Matlab functions and I want to distribute it to few people for testing. But I do not want to reveal the source to them. All these people have matalb installed on their systems. So I don't want to make standalone executable from my functions. Ideally I want something like complied library files which the users can put in the matlab path & call the functions from their matlab prompt / matlab functions. Is it even possible ?
Edit: I have matlab compiler toolbox. But the users won't be having access to matlab compiler toolbox on their matlab.

The standard way is using pcode. Look in the docs and remember to keep a copy of the source code elsewhere!

Related

How to call function from opnet [duplicate]

I have some code that plots triangles in MATLAB.
I need to be able to somehow execute this code from my C program which generates these points.
Is that possible? How can it be done?
Just a thought:
Can I somehow embed MATLAB code in C, so that it can compile on a C compiler?
The Mathworks site has full details; a demo video of calling the Matlab engine from C, and also the Matlab to C Compiler.
As mentioned previously by answerers, you can call a live copy of MATLAB from C via the MATLAB Engine interface.
If the end-product needs to be used where there is no live copy of MATLAB, you can deploy the application using MATLAB Compiler. However, MATLAB Compiler does not, as another answer has suggested, convert MATLAB programs into C code (and hasn't done for a few versions now). Instead, it archives and encrypts your MATLAB program, and packages it into an executable or shared library that executes against the MATLAB Compiler Runtime (shareable royalty-free). The executable or shared library can then be called from C.
Alternatively you could go the other way around, and call your C code from MATLAB, using either loadlibrary or MATLAB's MEX interface.
Update: As of release R2011a, you can also use MATLAB Coder to generate C code directly from a subset of the MATLAB language.
Look at this presentation about integrating MATLAB Algorithms in C or C++ Applications http://www.mathworks.com/videos/integrating-matlab-algorithms-in-c-or-c-applications-86431.html

How compile m-file without installed Matlab?

What is the simplest way to compile m-file without installed matlab?
And can someone say when will users get possibility for compiling programs with training networks (not only using training networks in compiling)?
MATLAB is not a compiled language, it is interpreted at runtime, so you need to have MATLAB installed to run a m-File (script). You can use the MATLAB compiler software to create a standalone application from an m-File or a function.
To run an m-file without having MATLAB, you can use GNU Octave. Octave is an open-source software which has almost the same syntax and functionality as MATLAB. They are not 100% identical though, so you will have to migrate your script. As mentioned in this question, code which runs in MATLAB will almost always run in Octave too, so it should work quite well.
for very basic scripting you can use this online octave(/matlab) compiler I found http://www.tutorialspoint.com/matlab/try_matlab.php There are some limitations of course, but for basic scripts it works well

How do I use built-in MATLAB functions?

MATLAB has lots of built-in functions that I can call, such as "sin" and "norm." However, some of MATLAB's built-in functions are part of different libraries that I cannot access directly. For example, the function "ssim" is part of MATLAB's image processing toolbox, so I cannot simply call "ssim" in my code and have it work.
How do I call built-in MATLAB functions that are in different libraries? Do I need to import the libraries somehow? If so, how do I do that? How do I do this for ssim specifically?
Thanks so much!
Type ver into the command window to see which toolboxes belong to the license you bought.
Any function of these installed toolboxes you can call normally, like the mentioned sin.
Sometimes, if you're lucky, you can find equivalent functions of otherwise expensive toolboxes at MATLAB File Exchange.

MATLAB Compiler vs MATLAB Coder

What's the difference between the two?
As far as I understand it, MATLAB Compiler wraps the MATLAB code into a .exe file so that it can be used without installing MATLAB, and only requires the MCR. On top of it MATLAB Builder NE can also be used to produce .Net assemblies to be used with .Net framework instead of the .exe file, but they still require MCR.
Now I don't understand what MATLAB Coder used for? It generates C/C++ code. But is the MATLAB code really converted into C/C++, or is it merely packaged like in the case of MATLAB Compiler? Does it also need the MCR to run?
I understand that this is not exactly a programming question. But I have searched the internet and still haven't found a clear answer. These are very expensive products so I would like to know what I am getting into.
MATLAB Compiler encrypts and archives your MATLAB code (which remains as MATLAB .m code), and packages it in a thin executable (either .exe or .dll) wrapper. This is delivered to the end user along with the MATLAB Compiler Runtime (MCR). If you wish, the MCR can be packaged within the executable as well.
The MCR is freely redistributable, and you can think of it as essentially a copy of MATLAB without a front-end desktop.
When the user runs the executable, it dearchives and decrypts the MATLAB code, and runs it against the MCR instead of MATLAB. Applications delivered via this method should therefore run exactly the same as they do within MATLAB (including the same speed).
MATLAB Coder converts a subset of the MATLAB language into C code. This can then be used in many different ways, including being brought back into MATLAB as a mex file, compiled with a C compiler to be called from another application, or delivered to an embedded device. Since it is C code rather than MATLAB code, it will often (though not always) run much faster than the original MATLAB code. The C code does not require the MCR. The supported subset of the MATLAB language is very extensive, but there are a few notable restrictions that you would want to look into before committing to this workflow. The code produced is C code, although it can produce a C++ wrapper if you have a need to use a C++ compiler rather than a C compiler.
MATLAB Compiler is intended for the use case that you want to simply and (fairly) straightforwardly share a MATLAB application that you've written with someone who does not have a copy of MATLAB. Since the deployed .m code is encrypted, it can also be used to share MATLAB code while protecting intellectual property.
MATLAB Coder has other use cases, such as wanting to speed up MATLAB code by converting to a mex file, or needing to produce C code for another application or an embedded device.
If you have more detailed questions, I would really recommend that you just call up MathWorks and ask them.
Edit: The information above is correct for versions of MATLAB R2014b and below. As of MATLAB R2015a, functionality from MATLAB Compiler has been remixed with functionality from the MATLAB Builder products, and there is also a new product MATLAB Compiler SDK.
As of R2015a, MATLAB Compiler works in the same way as described above (i.e. encrypt, archive and package, but not producing C), but will now package as .exe, and as an Excel add-in (.xla). Prior to R2015a, this functionality used to be present in the product MATLAB Builder EX for Excel.
As of R2015a, MATLAB Compiler no longer produces .dll components. This functionality has been moved to the new product MATLAB Compiler SDK, which also includes functionality to produce .NET assemblies and Java classes. Prior to R2015a, this functionality used to be present in the products MATLAB Builder NE for .NET and MATLAB Builder JA for Java.
In other words:
In R2014b and below, we had:
MATLAB Compiler: produce .exe and .dll components
MATLAB Builder NE for .NET: produce .NET assemblies
MATLAB Builder JA for Java: produce Java classes
MATLAB Builder EX for Microsoft Excel: produce Excel add-ins.
In R2015a, we have:
MATLAB Compiler: produce .exe and Excel add-ins
MATLAB Compiler SDK: produce .dll, .NET assemblies and Java classes.
The scope and use-cases of MATLAB Coder have not changed across these releases (although there are new features).
Edit: As of R2015b, MATLAB Compiler SDK also produces Python packages.
Additional information on distinguishing MATLAB Coder and MATLAB Compiler for C/C++ can be found here.
Comparison table of different MATLAB Products for code generation.
MATLAB Compiler SDK provides shared libraries that run against a MATLAB Runtime (MCR). It supports most of the features in MATLAB, including graphics, and protects your intellectual property by encrypting your MATLAB code.
MATLAB Coder, on the other hand, provides readable and portable source code. It supports a subset of the MATLAB Language focused on algorithms performing numerical computations.
This MATLAB Answers goes into more details comparing these two approaches:
http://www.mathworks.com/matlabcentral/answers/223937-should-i-use-matlab-compiler-sdk-or-matlab-coder-to-integrate-my-matlab-applications-with-c-c
For example, MATLAB Compiler SDK can be deployed only to platforms that support MATLAB (Windows, Mac, Linux) whereas MATLAB Coder generates C code that can run on any platform that supports C code.
Also, the packaged code from MATLAB Compiler SDK is encrypted to protect IP, whereas the generated C code from MATLAB Coder can be protected in the same way hand written C code is protected.
It's also worth noting that generated C code from MATLAB Coder has the potential of faster execution while the packaged code from MATLAB Compiler SDK will run as fast as it does in MATLAB.
I'm not an expert, but the Coder is described as generating standalone C/C++ code, making no mention of the MCR. I notice however that it says that it only supports a "subset" of the Matlab language, which you can read more about here. The Compiler appears to just package up your Matlab code as you suggested, so probably supports most features.
MATLAB coder generates C/C++ code, which could also depend on 3rd party libraries such as intel's TBB/IPP. If you want truly vanilla C/C++ code, you need MATLAB's embedded coder.
On the other hand, MATLAB compiler produces encrypted executables/libraries/etc which runs against MCR (Matlab runtime library). This requires the target computer to pre-install MCR (at no cost). Since MCR is over 1 GB in size, it's not very retargetable.
MATLAB coder is also more expensive than MATLAB compiler.

View HDF5 inside matlab

Just how good is MATLAB in opening and viewing HDF5 files? I can see there are a couple of h5... commands but I'm wondering if there is a way to "view" the file interactively as you could do with a .mat file or like HDFView tool?
We use Matlab and we use HDF5 files. We also use a lot of Fortran, and one of the reasons we use HDF5 is to store datasets which can be read and written both by Fortran and Matlab. Matlab vs Fortran for HDF5 is a bit like Matlab vs Fortran for most things, the former is easier to use, lets you try out ideas quickly, and gives you much tighter integration between data and visualisation. You may have your own views on Matlab vs your favourite compiled language.
Matlab provides a complete (maybe not entirely complete, but we haven't found any features of the HDF5 Fortran APIs that we want to use that Matlab doesn't provide) interface to HDF5. When you view the document that #GuntherStruyf pointed you at, read to the bottom where you can find information about Matlab's low-level HDF5 access functions. You can do a lot with the high-level access functions alone, but not everything. And if you are already used to the HDF5 API for Fortran/C/C++, taking the same approach in Matlab and ignoring the higher-level functions is easy enough.
But we do use HDFView too, it's an easy way to trawl through an HDF5 file and, within certain limitations, an easy way to quickly edit an HDF5 file. You can, for instance, cut and paste from Excel to HDFView; perhaps more relevant you can cut and paste from Matlab's variable editor. Matlab doesn't quite provide that level of easiness for viewing HDF5 files.
To sum up:
HDFView for viewing and interactive editing
Matlab for programming for prototyping and rapid deployment
Fortran/C/C++ for programming for heavy-lifting.