I'm not going to describe how to transform the MATLAB function to c++ code, there is a nice video that already explain how to do it, what is not explained is what to do when you get an error while your typing the Matlab command
>>coder
??? Undefined function or variable 'coder'.
Struggling to understand what was the problem after a while I found out that was my Matlab version,
>> ver
-------------------------------------------------------------------------------------
MATLAB Version 7.9.0.529 (R2009b)
MATLAB License Number: xxxxxxxxx
Operating System: Microsoft Windows Vista Version 6.1 (Build 7600)
Java VM Version: Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
-------------------------------------------------------------------------------------
By installing a new version of Matlab
>> ver
---------------------------------------------------------------------------------------------
MATLAB Version: 8.2.0.701 (R2013b)
MATLAB License Number: xxxxxxxx
Operating System: Microsoft Windows 7 Version 6.1 (Build 7600)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) Client VM mixed mode
---------------------------------------------------------------------------------------------
The problem is gone.
Hope this helps.