Borrar filtros
Borrar filtros

Matlab to C code generation readiness error

5 visualizaciones (últimos 30 días)
Newman
Newman el 22 de Jun. de 2015
Respondida: Walter Roberson el 22 de Jun. de 2015
i want to convert my mat-lab code to c code but then when i am checking the code generation readiness then it is showing that some functions calls are unsupported.
Do i need to change these functions i mean write any alternatives ????I am using matlab 2015 version .If yes then pls tell me the alternative code for these functions/code:
fieldnames function:
fn0 = fieldnames(varargin{1});
accumarray function:
D = accumarray(subs, -x(M,3).*wM, [numel(Il),1]);
exist function
if exist('pars','var')
pars = optionmerge(pars0,pars);
whos function
t = whos('Il');
if ~strcmp(t.class,'double');
Il = double(Il);
eval function
eval('y = x(1+siz(1):rows-siz(1), 1+siz(2):cols-siz(2), 1+siz(3):layers-siz(3));')
rmfield function
pars = rmfield(pars,'algorithm');

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Jun. de 2015
C does not have dynamic creation of variables. Variables are either in scope or not. If you find yourself checking to see if a variable exists then you have done something wrong in C.
Now, checking to see whether a pointer points to NULL is, on the other hand, a common operation in C. This is similar to initializing MATLAB variables to [] and later checking isempty()
C does not keep a list of which variables are in scope so whos() is not effective. If you want to check the data type of a variable then use isa() . But remember that C doesn't have dynamic typing, so you should write your routines to expect particular data types and at most use assert(isa(Il,'double')) to hint to the code generator what the datatype must be. In C any given parameter must have a specific datatype (In C, that datatype could be a union but in C the programmer is responsible for keeping track of which of the possibilities is the correct one at any given time.)
fieldnames() -- a nuisance, but again in C every object has a fixed datatype and if that fixed type is a union you need to program in the keeping track. If the fixed type is a struct then it is a particular struct, the field names of which should be known to the programmer. The documentation page http://www.mathworks.com/help/coder/ug/how-working-with-structures-is-different-for-code-generation.html might say something useful but I do not have the license needed to read that documentation.
accumarray() -- basically convert it to a loop totaling the entries.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by