error in embedded matlab function
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi, how to resolve this type of error: Function output 'x'and 'y' cannot be of MATLAB type. where x&y are the output of my function, i use for their calculation, radtodeg()
0 comentarios
Respuestas (3)
Azzi Abdelmalek
el 20 de Mayo de 2015
Editada: Azzi Abdelmalek
el 20 de Mayo de 2015
Some function are not supported for c code generation. You can tell Matlab that you do not need code generation for those functions by inserting in your function block
coder.extrinsic('radtodeg')
Walter Roberson
el 20 de Mayo de 2015
When you call a MATLAB function in a MATLAB Function Block, you usually need to assign the result to a variable and then use the variable, instead of using the result in an expression. As a simple example,
y = abs(sin(x));
you might need to rewrite as
t = sin(x);
y = abs(t);
This does not have to do with whether the routine is supported for code generation: it is a restriction on how you can use the results of calling a MATLAB routine.
2 comentarios
Ryan Livingston
el 2 de Jun. de 2015
Editada: Ryan Livingston
el 2 de Jun. de 2015
This answer isn't true in general. Results of function calls can typically be used in expressions in a MATLAB Function Block. Only in some cases when the function being called has been declared extrinsic, does the output need to be assigned to a variable whose datatype is known.
Ryan Livingston
el 2 de Jun. de 2015
Since you've declared radtodeg as an extrinsic, its output needs to be pre-assigned to a value that tells Simulink what the output size, type, and complexity of radtodeg will be. So if radtodeg always returns an array of the same size as its input you could use:
y = u; % assign example of correct size, complexity, and type
y = radtodeg(u); % call extrinsic function
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!