Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add "help"-text to a mex-function?

I am writing a Matlab mex-file. However, mex-files seem to have a serious limitation: help mexfilename won't cause a help text to appear.

I could circumvent this by writing a m-file, that ultimately calls the mex-file, but includes help, but there has to be a better way.

On the other side, that way I could do all the error-checking in the m-file, where it is far more convenient to do so...

like image 690
bastibe Avatar asked Feb 10 '09 13:02

bastibe


People also ask

How do you use the MEX function?

A MEX function behaves just like a MATLAB script or function. To call a MEX function, use the name of the MEX file, without the file extension. The MEX file contains only one function or subroutine. The calling syntax depends on the input and output arguments defined by the MEX function.

What is MEX command?

A MEX file is a function, created in MATLAB, that calls a C/C++ program or a Fortran subroutine. A MEX function behaves just like a MATLAB script or function. To experiment with calling MEX functions, use the code in Tables of MEX Function Source Code Examples to build and run examples.


2 Answers

I believe PierreBdR is right; you would create an m-file version of your function with just the header call and comment block, but no body.

It might not be a bad idea to put the error checking for the inputs in the m-file, then have the m-file invoke the mex-file (you may have to give them different names, though). It may be more straight-forward to check variables in MATLAB (using, for instance, built-ins like nargchk) and put them into a standard format that you may always want the inputs to the mex function to have. Many of the Image Processing Toolbox functions that I've looked at seem to do this (formatting and checking data in the m-file then doing the expensive computations in a mex-file).

like image 103
gnovice Avatar answered Sep 20 '22 18:09

gnovice


You have to create an m-file (name.m) with the same name as your mex-file (name.c). Then, you put the function declaration and help text, but no function body. Example:

function [o1,o2] = MyFct(i1,i2,i3)
% MyFct takes 3 arguments and returns 2 ...      
like image 43
PierreBdR Avatar answered Sep 23 '22 18:09

PierreBdR