Why am I getting the error "found unsupported dynamic matrix type" in HDL Coder R2024b?

5 views (last 30 days)

I am currently using HDL Coder in MATLAB R2024b to generate fixed-point code for a function "DUT". I want to modify the size of "DUT" output arrays from the test bench script "TB.m" by passing a variable, "array_len". The "array_len" will be chosen from the test bench at random. Example code is given below:

%% TB.m:
MAX_SIZE = 10;
array_len = randi(MAX_SIZE);
out = DUT(array_len);

%% DUT.m
function output = DUT(array_len)
output = ones(array_len);
end
When I try to generate code for "DUT" using HDL Workflow Advisor, I receive the errors below. Why is this?

DUT:0 Error Found unsupported dynamic matrix type at output port: 1, name 'out', in the file/function DUT.
DUT:0 Error MATLAB HDL Coder failed in the code generation phase.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Aug 2025 at 0:00
Output variables for a function ("DUT") generated using HDL Coder must have a pre-defined size. The following workaround may help you achieve the desired workflow:
If you know the largest output array you intend to return, you may consider modifying "DUT" to allocate an array of that size. In the Test Bench, only extract the data from the relevant portion of the output array. This allows you to utilize variable sized outputs without dynamically allocating memory. See the example below:
%% For "TB.m":
MAX_SIZE = 10;
array_len = randi(MAX_SIZE);
out = DUT();
relevant_out = out(1:array_len);
%% For "DUT.m":
function output = DUT()
MAX_SIZE = 10;
output = ones(MAX_SIZE);
end
  1 Comment
Kiran Kintali
Kiran Kintali on 29 Aug 2025 at 14:32
You can also input parameters to DUT which can be defined as constants so that you do not need to hard code the MAX_SIZE inside the DUT.
%% TB.m:
MAX_SIZE = 10;
array_len = randi(MAX_SIZE);
out = DUT(array_len);
%% DUT.m
function output = DUT(array_len)
output = ones(array_len, 'uint8');
end
%% RUNME.m
MAX_SIZE=10;
hdlCfg = coder.config('hdl');
codegen -args {coder.Const(MAX_SIZE)} -config hdlCfg -report DUT

Sign in to comment.

More Answers (1)

Kiran Kintali
Kiran Kintali on 29 Aug 2025 at 14:21

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!