tags:

views:

327

answers:

2

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

+4  A: 

If I remember, you have to create an m-file with the same name as your mex-file. Then, you put the function declaration and help, but no function body. Example:

function [o1,o2] = MyFct(i1,i2,i3)
# MyFct takes 3 arguments and returns 2 ...
PierreBdR
+4  A: 

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

gnovice

related questions