I am reading on the Matlab help about coder.varsize. In particular, I read that Declare Variable-Size Array with a Mix of Fixed and Variable Dimensions Specify that A is an array whose first dimension has a fixed size of three and whose second dimension has a variable size with an upper bound of 20. function fcn() ... coder.varsize('A',[3 20], [0 1] ); ... end I am not sure I understand how to fix the first dimension, but declaring the second dimension as "Inf", so no upperbound at all. From what I understand here, I always need to give an upperbound, when I have a mix of fixed and variable dimensions. Is that correct, or there is a way to fix one dimension, and specify the second dimension as unbounded?
Neeta Dsouza answered .
2025-11-20
What does it mean by fixed dimesion ? Consider below example
function [x,y] = usevarsize(n)
%#codegen
x = 1;
%x = ones(2);
coder.varsize('x',[1 12],[0 1]);
y = size(x);
if n > 10
x = 1:n;
end
codegen usevarsize -args {0} -report
>> usevarsize_mex(11)
ans =
1 2 3 4 5 6 7 8 9 10 11
>> usevarsize_mex(14) Error using usevarsize (line 8) Size overflow error on dimension 2: upper bound is 12, but actual size is 14.
function [x,y] = usevarsize(n)
%#codegen
x = 1;
%x = ones(2);
coder.varsize('x',[1 inf],[0 1]);
y = size(x);
if n > 10
x = 1:n;
end
Here I am declaring the second dimension of 'x' as unbounded. So 'x' can be any length 1-D vector :
codegen usevarsize -args {0} -report
>> usevarsize_mex(24)
ans =
Columns 1 through 22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Columns 23 through 24
23 24