Why can't Simulink inherit signal sizes?

11 views (last 30 days)
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

Accepted Answer

Mark McBroom
Mark McBroom on 10 Nov 2018
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);
  1 Comment
Tobias N
Tobias N on 10 Nov 2018
Yes that would work. Thank you. My concern is just, that Simulink actually does figure out what the size of y is in all of these functions in the model. Just in this specific one it doesn’t work.

Sign in to comment.

More Answers (0)

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2014b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!