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

41 次查看(过去 30 天)
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?
  1 个评论
Chiluveru
Chiluveru 2023-2-13
hi Raghu,
I am alsp facing same issue like the error below:
Size mismatch (size [1 x 0] ~= size [16 x 0]).
need your help for solving it

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2022-8-15
...
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 个评论
Bruno Luong
Bruno Luong 2022-8-17
编辑:Bruno Luong 2022-8-17
Your code is too long for me to look in detail. I notice that the code is not even optimized (growing array, call function in the loop, some common calculation is repeated, some constant quantity is computed inside the loop, etc...)
My recommendation is working on your matlab code before feed it to the coder.
zhou caiwei
zhou caiwei 2022-8-18
you are right, I think I should optimize my code.Is there any reference materials?

请先登录,再进行评论。

更多回答(1 个)

Raghu Boggavarapu
Raghu Boggavarapu 2022-8-25
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.
  3 个评论
Walter Roberson
Walter Roberson 2023-2-13
You are assigning an empty array with 16 rows to a variable that was first assigned an empty array with one row.
When you use MATLAB Function Blocks in Simulink, then unless you use coder.varsize then the first assignment to a variable sets the limits on how large the variable is. This is different from regular MATLAB as regular MATLAB adjusts sizes as needed.

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by