Output 'y' has variable size but the upper bound is not specified; explicit upper bound must be provided.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
y = 10
coder.varsize('y', [1,20000]);
These lines of code are inside a for loop and I expect the size of the variable y to increase. This is MATLAB function. I get the following error "Output 'y' has variable size but the upper bound is not specified; explicit upper bound must be provided." I have taken a look at other examples but couldn't find a solution to it.
I even checked the box for variable size in ports and data manager of the function.
Please let me know how can I fix this error. Help is appreciated.
3 comentarios
Tim Gerbert
el 6 de Nov. de 2020
Hi,
I have similar problem and checked point 4 in Simulation Target --> Advanced parameters category:
"Make sure that the model is configured for dynamic memory allocation:
- The Dynamic memory allocation in MATLAB functions check box is selected.
- The Dynamic memory allocation threshold in MATLAB functions parameter has the default value 65536."
I have attached an example. Can you provide help?
Thanks and Kind Regards
Tim
Leon
el 19 de Dic. de 2022
Hi,
I do also have such problem, but I can't find any solutions.
Have you resolved this issue?
Respuestas (1)
Jaimin
el 2 de En. de 2025
The error message you are seeing is linked to MATLAB's requirements for code generation. When employing MATLAB Coder to generate code, it is necessary to explicitly define the upper limit for variable-size arrays. This is crucial for the code generation process to allocate memory efficiently.
Here is how you can address the issue:
- Ensure that you have specified the upper bound for the variable y correctly using the “coder.varsize” function. In your case, it seems you've already set [1, 20000] as the upper bound, which should be correct. However, make sure this line is executed before any operations that change the size of “y”.
- Initialize “y” with a size that matches the expected maximum size or an initial size that can be expanded. This ensures that MATLAB Coder understands the dimensions you are working with.
Kindly refer following code for understanding.
function myFunction()
% Declare y as a variable-size array with an upper bound
coder.varsize('y', [1, 20000]);
y = zeros(1, 10);
for i = 1:1000
newSize = min(20000, length(y) + 10);
% Ensure the output of someFunction matches newSize
y(1:newSize) = someFunction(newSize); % Pass newSize to match output size
end
end
For more information kindly refer following MathWorks documentation.
I hope this will be helpful.
0 comentarios
Ver también
Categorías
Más información sobre Software Development Tools en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!