Why do I get an error when converting my MATLAB code (which utilizes "bwlabel") to C code using MATLAB Coder?

I am trying to generate C/C++ code from my MATLAB program, which utilizes "bwlabel".
However, I encounter the following error message:
??? Computed maximum size of output #1 of function 'intermediateLabelRuns' is not bounded.
Static memory allocation requires all sizes to be bounded.
The computed size is [:? x 1].
Please consider enabling dynamic memory allocation to allow unbounded sizes.
Here is an excerpt of my example code:
im_bin = zeros(dim_X,dim_Y);
coder.varsize('im_bin');
for idx=1:dim_X
for idy = 1:dim_Y
if (im(idx,idy) < threshold)
im_bin(idx,idy) = 0;
else
im_bin(idx,idy) = 1;
end
end
end
[label, nblabel] = bwlabel(im_bin, 4);

 采纳的回答

A possible cause of this error message Dynamic Memory Allocation During Code Generation is disabled. Please check the coder configuration to see if something similar to the following segment exists:
cfg = coder.config();
cfg.DynamicMemoryAllocation = 'Off';
codegen -config cfg ...
Replacing "Off" with one of the other choices for "DynamicMemoryAllocation" will avoid the issue.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB Coder 的更多信息

产品

版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by