MATLAB Coder™ generates standalone C and C++ code from MATLAB® code. The generated source code is portable and readable.MATLAB Coder supports a subset of core MATLAB language features, including program control constructs, functions, and matrix operations. It can generate MEX functions that let you accelerate computationally intensive portions of MATLAB code and verify the behavior of the generated code.
Questions tagged [matlab-coder]
275 questions
46
votes
4 answers
MATLAB Compiler vs MATLAB Coder
What's the difference between the two?
As far as I understand it, MATLAB Compiler wraps the MATLAB code into a .exe file so that it can be used without installing MATLAB, and only requires the MCR. On top of it MATLAB Builder NE can also be used to…

Win Coder
- 6,628
- 11
- 54
- 81
11
votes
2 answers
How MATLAB code generation infers output size with nested branches
When generating C code using MATLAB Coder, the behaviour is different when an if happens in body of another if or in its elsesection. The following case easily creates C code with output having size 5x5:
function y = foo1(u)
if u > 0
y =…

Mohsen Nosratinia
- 9,844
- 1
- 27
- 52
11
votes
2 answers
Python ctypes definition for c struct
I am trying to call some c code generated by the Matlab coder. Matlab uses a c struct called emxArray to represent matrices (documented here:…

Trevor Sweetnam
- 123
- 1
- 1
- 7
8
votes
1 answer
How to identify places in MATLAB where data is stored outside the bounds of an array?
I am trying to use MATLAB Coder to convert code from Matlab to a MEX file. If I have a code snippet of the following form:
x = zeros(a,1)
x(a+1) = 1
then in Matlab this will resize the array to accommodate the new element, while in the MEX file…

Alex319
- 3,818
- 9
- 34
- 40
7
votes
2 answers
Iterate through a structure in MATLAB without 'fieldnames'
The usual way to iterate through a struct data type in MATLAB is using the fieldnames() function as done in:
mystruct = struct('a',3,'b',5,'c',9);
fields = fieldnames(mystruct);
for i=1:numel(fields)
mystruct.(fields{i});
end
Unfortunately,…

unndreay
- 353
- 3
- 7
7
votes
2 answers
get string of enum - matlab coder
I have an enum like this:
classdef(Enumeration) bla_type < int32
enumeration
bla_one(1)
bla_2(2)
end
end
I can get the 'string representation of an element' like this:
char(bla_type.bla_one)
=>
bla_one
Unfortunately,…

cs0815
- 16,751
- 45
- 136
- 299
6
votes
4 answers
Convert integer to string with C++ compatible function for Matlab Coder
I'm using Matlab Coder to convert some Matlab code to C++, however I'm having trouble converting intergers to strings.
int2str() is not supported for code generation, so I must find some other way to convert ints to strings. I've tried googling it,…

ein123
- 63
- 1
- 3
5
votes
1 answer
Constants and Matlab Coder
Some functions requires the input to be a constant, when run in Matlab Coder. I wish to find a way to declare the input as a constant before it is input as an example for the problematic situation:
function foo = subsubfunction(x,y)
…

Michael Ward
- 213
- 5
- 12
5
votes
2 answers
Adjacent and non-adjacent superpixels for an superpixel in an image
After segmenting an image into N superpixels, I need to specify the superpixels that are adjacent or non-adjacent to one superpixel and determine this relationship for all superpixels.
[L,NumLabels] = superpixels(A,200);
How can I specify the…

dtr43
- 135
- 7
- 19
5
votes
1 answer
switch-case with multiple matches in matlab for code generation
The following code is valid matlab sytax to check whether b matches any elements in a. However, if the code is used for code generation (i.e. simulink) then I get the error:
'code generation only supports cell operations for varargin and…

craq
- 1,441
- 2
- 20
- 39
4
votes
1 answer
Cannot convert Matlab code to C code using Matlab Coder
I have a MATLAB code shown in below. I am trying to convert this code to C code using MATLAB Coder but I encountered an error.
Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the…

theGuardianDevil
- 78
- 8
4
votes
1 answer
How to use C code generated by Matlab?
I used the Matlab Coder to produce C code for a simple Matlab Array adding function which adds the elements of two arrays. Once done, the Matlab Coder gives me a package containing .c and header files ( which also includes a C file of the function…

Ahmad Shah
- 199
- 4
- 14
4
votes
1 answer
Is there any difference between a mex file and a function called with coder.ceval?
related
My goal is to use a mix of C code and Matlab code, and ultimately have the whole thing run in C by using the Coder tool.
I've found 2 ways of incorporating C into Matlab, writing a Mex file, and using coder.ceval on a C program.
Is there any…

GreySage
- 1,153
- 19
- 39
4
votes
3 answers
How can I package a MATLAB application that utilises toolboxes?
I want to package up an application in MATLAB for another team to use. They will have an appropriate version of MATLAB to run this application, but they might not necessarily have licenses for all the toolboxes used by the application.
Is there a…

Samuel O'Malley
- 3,471
- 1
- 23
- 41
4
votes
5 answers
Integrating Matlab Coder with c#
I want to integrate MATLAB Coder output with a C# project in Visual Studio 2010. My main idea is:
Create a *.m script in Matlab
Make sure the script is compatible with Matlab Coder.
Generate a C++ shared library (DLL) with Matlab Coder
Integrate…

guilhermecgs
- 2,913
- 11
- 39
- 69