Why can't Simulink inherit signal sizes?

11 次查看(过去 30 天)
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

采纳的回答

Mark McBroom
Mark McBroom 2018-11-10
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 个评论
Tobias N
Tobias N 2018-11-10
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by