MATLAB Answers

0

Why can't Simulink inherit signal sizes?

Asked by Tobias N on 31 Oct 2018 at 13:50
Latest activity Commented on by Tobias N on 10 Nov 2018 at 21:43
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

  0 Comments

Sign in to comment.

Products


Release

R2014b

1 Answer

Answer by Mark McBroom on 10 Nov 2018 at 16:23
 Accepted 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);

  1 Comment

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.