Variables of varying size in Simulink – avoiding preallocation
I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated.I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated. I have a matlab script that controls a Simulink model for code generation. Currently I preassign a varaible X to be the maximum possible size of the array (100 rows) along with a constant 8 columns. A coplicated for loop code block runs to decide which of the variables looped over will get added to the variable X. Depeding on settings this can be anywhere between 6 rows and 100 rows filled. It seems very cumbersome to have a 100×8 permanently when there is eg only info in the top 6×8 portion as this matrix then gets used by other Simulink submodels. All my attempts at creating a varaible array size have come up against issues with errors such as ‘Error in port dimensions’. Is there any way for Simulink to avoid preallocating the variable size or reducing the size of the array once populated. simulink, variable, matrix array MATLAB Answers — New Questions









