matlab coder report Size mismatch (size [0 x 0] ~= size [1 x 2])

13 views (last 30 days)
I tried to use matlab coder to convert my matlab file into C\C++ source file. In my *.m file,I defined a dynamic array:
...
coord_list = [];
I_list = [];
...
for i=1:n
....
coordinate = yy;
I = zz;
coord_list = [coord_list;coordinate];
I_list = [I_list;I]
end
The error occurs like:
??? Size mismatch (size [0 x 0] ~= size [1 x 2]).
The size to the left is the size of the left-hand side of the assignment.
How could I fix this bug? how should I modify my matlab code so that It meets the requirements of C\C++ style for matlab-coder?

Answers (2)

Raghu Boggavarapu
Raghu Boggavarapu on 25 Aug 2022
Hi,
MATLAB Coder supports growing an array only by concatenation, growing an array by index is not supported. Please see: https://in.mathworks.com/help/coder/ug/limitations-with-variable-size-support-for-code-generation.html
If you wish to assign varying sized arrays to same variable, you can use coder.varize .
Also if you would like to optimize the MEX runtime, you can try disabling IntegrityChecks and ResponsivenessChecks in the MEX coder config.

Chunru
Chunru on 15 Aug 2022
...
coord_list = zeros(n, m1); % m1 is the length of yy below
I_list = zeros(n, m2); % m2 is the lenght of zz
...
for i=1:n
....
coordinate = yy;
I = zz;
coord_list(i, :) = coordinate;
I_list(i, :) = I;
end
  14 Comments
zhou caiwei
zhou caiwei on 18 Aug 2022
you are right, I think I should optimize my code.Is there any reference materials?

Sign in to comment.

Categories

Find more on Triangulation Representation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by