MATLAB: Can’t Simulink inherit signal sizes

MATLABmatlab functionsimulink

Hello,
I'm having a problem with inherited signal/vector sizes in my simulink model. I've got input signals that respresent vectors of the size 50 and I need to shift the values to the left /right while setting the last/first corresponding values to zero depending on where the values were shifted. E.g.: [1 2 3 4 5] -> [0 1 2 3 4] I use the following matlab function for shifting right (left shifting is analogous):
function y = shiftVectorRight(u,indx,dim)
%#codegen
y=circshift(u,indx,dim);
for ii=1:indx
y(ii)=0;
end
Now I got the following error, when Updating/Running the model for one of these functions in the model:
Inferred size ('[50]') for data 'y' does not match specified size ('scalar').
The data type and size of the signals of the MATLAB function is set to inherited and all input signals to the system have a consistent length and I got several of these blocks in the system (but just one triggers this error). As you can see. On the first function Simulink can't inherit the size, on the second it can. (Other Shift Vector Right Functions do work in the model. )
Why cant simulink inherit the correct size? Is there a way to fix this without setting the output signal size of the function?
Thanks in advance Greetings

Best Answer

try adding the following line of code after %#codegen statement. Since idx is an input to your function, Simulink isn't able to figure out the size of y. A statement like the following provides tells Simulink that it is a vector of 50.
y = zeros(50,1);
Related Question