Why do I get an error generating code from a MATLAB class that can conditionally assign multiple data types to one of its properties in MATLAB Coder 2.2 (R2012a)?

3 visualizaciones (últimos 30 días)
I have created a MATLAB Class called 'sampleClass' which contains a property called 'sampleProperty'. The class is initialized with a single argument 'caseNum' as follows:
function obj = sampleClass(caseNum)
if caseNum == 1
obj.sampleProperty = uint8(1);
else
obj.sampleProperty = uint16(1);
end
end
In this way, the property is assigned to a uint8 data type if 'caseNum' is 1, and a uint16 data type otherwise. This works without any issues in MATLAB, but when I use MATLAB Coder 2.2 (R2012a) to generate code using this class, I get the following error:
??? Class mismatch (uint8 ~= uint16).
The class to the left is the class of the left-hand side of the assignment.
Is there any way I can work around this?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 21 de Ag. de 2012
The ability to assign a different data type to the property of a MATLAB Class based on some conditional statement is not supported for code generation using MATLAB Coder 2.2 (R2012a).
As a workaround, you can create two different properties of different data types and include the appropriate logic in your code to use the correct property based on this conditional statement.

Más respuestas (0)

Categorías

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

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by