File Exchange

image thumbnail

Using Legacy Code with MATLAB Coder

version (7.87 KB) by Anders Sollander
Some examples on building MATLAB code with existing C code

1 Download

Updated 01 Sep 2016

View Version History

View License

This file exchange submission contains some examples on how to include
custom C code when using MATLAB Coder, and how to support an implementation
for standard MATLAB functions not supported by MATLAB Coder. It also shows
how the build process can be more streamlined.
More information may be added here later, but for the moment, the examples must be understood by reading them.
The code in this example is described in more detail in this article:

Cite As

Anders Sollander (2021). Using Legacy Code with MATLAB Coder (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)


Thanks for the share!

For one reason the MEX-ed my_alg-routine is slower then the original one.

tic; my_alg(1e3); toc;
Elapsed time is 0.069168 seconds.
tic; my_alg_mex(1e3); toc;
Elapsed time is 1.410066 seconds.

Is that reasonable or I'm doing something wrong?

Stefano Gianoli

Excellent work! May I suggest to change the last line in the script kvs_script.m to:

>codegen('-config:mex', '-I', fullfile('.', '+mlcutils'), '-o', fullfile('.', '+mlcutils', 'kvs_mex'), 'kvs', '-args', 'ARGS')

so the script will run platform independent.


Good submission. All three examples worked.

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!