The error is because the following expression '100-max(size(k))-100' evaluates to a negative integer within 'zeros' -
zeros(100-max(size(k))-100,1) ---> zeros(100-(100)-100,1) ---> zeros(-100,1)
As per documentation, negative input arguments within 'zeros' function are treated to be 0 and 'zeros(-100,1)' gives an empty double column vector when run in MATLAB.
But in Simulink, MATLAB Function blocks are stricter (for reasons of code generation) and whenever a negative argument, which is dependent on the input to the Function block, is used in the 'zeros' function in the MATLAB Function block, it errors out.
The following simple model demonstrates the behaviour -
Here, an input argument to the 'zeros' function is dependent on the input variable 't' and evaluates to -1. Hence we get the error:
However, the error does not come up when the negative input arguments to the 'zeros' function, if used, do not depend on any input data. For example, if 'val', in the above code, is changed to the following, the model runs just fine -
The same issue is coming up in your model, since the 'zeros' in the MATLAB Function Block is accessing a negative input argument, which is dependent on the input to the function, causing the error.
To prevent such errors, you can wrap the expression used in 'zeros' in a way such that if the expression ever evaluates to < 0, it gets treated as zero. For example, changing the original expression to the following, avoids all such errors.
zeros(max(100-max(size(k))-100,0),1)
Hope this helps!