Why do I get a size mismatch error during code generation but not during regular MATLAB execution?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 5 de Mzo. de 2018
Respondida: MathWorks Support Team
el 6 de Mzo. de 2018
I have the following MATLAB function:
function example()
x = [1 2 3];
y = [1 2 3; 4 5 6; 7 8 9];
z = x+y;
When I run it by executing the following in MATLAB Command Window:
example()
I receive no error.
But, if I perform code generation either using the MATLAB Coder app or "codegen", I received the following error: ERROR: Size mismatch (size [1 x 3] ~= size [3 x 3])
Respuesta aceptada
MathWorks Support Team
el 21 de En. de 2019
The reason you see the error is because implicit expansion is not supported by code generation. As a workaround, you may consider using the "bsxfun".
For example, this line of code
z = x+y;
uses implicit expansion where the variable "y" is expanded to the same size as "x" before the sum is implemented by MATLAB. However, implicit expansion is not supported by code generation, and thus, you receive an error. Instead, as a possible workaround, you may consider this line of code
z = bsxfun(@plus,y,x);
where "bsxfun" explicitly sums each slice of "x" with "y".
For more details about the "bsxfun" function, you can refer to this page:
For a complete list of code generation supported features, you can refer to this page:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder 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!