Filter löschen
Filter löschen

Coder: Exclude/ignore code sections?

27 Ansichten (letzte 30 Tage)
Alex
Alex am 25 Okt. 2013
Kommentiert: Jan Siegmund am 18 Mär. 2020
I'm using coder to generate C source code. Of course many matlab functions are not available for coder. But I still want to use these functions when running the code in matlab.
Currently I have to comment out all these sections that are not coder-friendly when doing C source code generation. Is there something I can wrap them in to make the coder ignore them?
  1 Kommentar
Sean de Wolski
Sean de Wolski am 4 Nov. 2013
Alex, please contact technical support and let them know what functions you would like code generation support for.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mike Hosea
Mike Hosea am 28 Okt. 2013
You can wrap them with
if coder.target('MATLAB')
...
end
Or if that gives an error,
if isempty(coder.target)
...
end
You can also declare unsupported functions as "extrinsic" and use them in generated mex files. This practice has some pitfalls, and where unsupported data structures are involved, it can rather involved and advanced. However, in the simpler cases it is very simple. If foobar() is MATLAB function that you are passing, say, an m-by-n matrix to, and foobar returns, say, a 1-by-n vector (for example, this is what SUM would do with an m-by-n matrix where neither m nor n is 1), you would write:
coder.extrinsic('foobar');
y = zeros(1,size(x,2));
y = foobar(x);
Or, if you don't want to mess with coder.extrinsic:
y = zeros(1,size(x,2));
y = feval('foobar',x);
The y = zeros(...) line looks like wasted effort, but what it really does is tell the compiler what to expect by the next line, so it can copy the data from the MATLAB return into local storage. Basically, if you know what a function will return given the type of the input, then you just initialize the output variable to the appropriate type and then call the function.
  7 Kommentare
Jan Siegmund
Jan Siegmund am 16 Mär. 2020
Converting to a function handle is possible, but how about combined logic, like
@(x) ~isempty(x) && ~isvector(x)
?
Jan Siegmund
Jan Siegmund am 18 Mär. 2020
Update: and even function handles are not supported:
'@ischar' function handles are not supported for fixed-point conversion.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Generating Code finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by