MATLAB Mex files - matlab

Is there a way to get the mex file for a built-in MATLAB m- file? If yes, how? If no, does that mean I have to write the C code myself (oh nooo!!!)

The Matlab built-in functions are closed-source. Thus, you won't be able to get the code for them. It is possible to call Matlab functions from C code, though, if that solves your problem.
Depending on the function you want, you can find some of it elsewhere. For example, linear algebra operations are in LAPACK, and you may be able to get something from the source of OCTAVE.

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 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.

is there a faster version of fminbnd in matlab?

I am now using fminbnd in Matlab, and I find it relatively slow (I am using it inside a nested loop). The function itself, its interface and the values it returns are great, but when looking into the .m file I see it is not optimized. As a matter of fact, I was hoping for something like that to be written as a mex.
Anyone knows of an alternative to fminbnd that works much faster and does not have as much overhead?
It's written like that because it has to evaluate (feval) your user-defined function(s) on every iteration. Matlab's ODE solvers work in the same way. In current Matlab it's costly for a C/C++ code to call a user-defined Matlab function and read in its return values iteratively.
Make sure you're using the options correctly, that fminbnd is the correct tool (maybe a simpler scheme would be better or, since this in a loop, maybe a multi-dimensional method like fminsearch would be more appropriate), and have optimized your objective function. The next easiest thing would be to try compiling your Matlab code to C or C++ (see codgen). You'll likely need to compile in your objective function, and all of the options, as well in order to avoid the slowdown issues mentioned above. I've not tried this for fminbnd, but I did see mention of it working online. If your objective function itself is complicated, you could try just converting it to a mex function.
fminbnd is based on Brent's method. You can find C, C++, and FORTRAN code for that here. The GSL also has a version: gsl_min_fminimizer_brent.

Gaussian hypergeometric function 2F1

I would like to know if there is any available Gaussian hypergeometric function (2F1 function) code for Matlab.
I perfectly know that in the newest Matlab releases there is the hypergeom function, but it works really slow.
Therefore I was wondering about the existance of any mex function or whatever similar code performing what hypergeom does.
I thank you all in advance for support.
Best regards,
Francesco
The GNU Scientific Library implements hypergeometric functions including 2F1. You shouldn't have too much trouble wrapping that inside a mex-file.
I expect you'll find other sources knocking around on the Internet too.
Do report back and let us know if it does work faster than the intrinsic function.
After googleing a bit in the Internet, I came up with this tool provided within the Mathworks File Exchange:
http://www.mathworks.com/matlabcentral/fileexchange/35008-generation-of-random-variates/content/pfq.m
It consists of 1900 distributions, and among them the Gaussian hypergeometric function 2F1.
Furthermore, it has better performances than the standard hypergeom function.

Distribute matlab functions without source

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!