Hi all,
this question has been posted quite a few times but the solutions somehow don't work for me.
I have a simple simulink function of the form
fun [a,b] = myfun(c,d,e)
a = c-d;
b = d-e;
c,d, and e are vectors of the same constant size throughout the whole simulation.
previously, the Simulink model compiled without problems, but after a restart it gives the error: "Size mismatch (size [1x1] ~= size[5x1])" for a, and b. It doesn't make sense. I already tried to
  1. preallocate both variables with zeros(size(c))
  2. use bsxfun(@minus,c,d)
  3. restart the program, matlab, my computer
Yesterday evening, everything worked fine and I did change nothing in the code, only restartet my pc. The only thing that seems to be working is specifying the size of a and b in the model explorer. Since I start the simulation with different sizes of c,d, and e (all the same size though), it is not feasible for me to change it everytime.
It seems to be a common problem. Does anyone have a solution?
Thank you a lot in advance!

 채택된 답변

Alexandros Papadopoulos
Alexandros Papadopoulos 2019년 3월 8일

0 개 추천

Okay I figured part of it out. The function gets called through a matlab function block in simulink. The inputvariables are taken from two ways.
a) c is taken from a constant block which references a variable in the work space,
b) b ist the change of e, which is passed through an integration block (1/s) and then becomes the input e. So take e -> calculate b --(leave the function)--> integrate --(enter function)--> become e.
you have to be careful to uncheck the "Interpret vector as 1-D"-box in the constat. It's default setting is "checked" when you take it out of the library. The same holds true for the initiation value of the integrated constant: the value of b is initiated inside the integration-block. In my model, the value here needs to be a vector as well. A simple fix is to initiate the value externally and use a constant block of a varible from the workspace, which you create by repmat(ini_value,size(variable));.
I didn't figure out why the simulation did work on one day and not on the other. It seems to be a well docuemnted problem and probably relates to the compiling routine behind the simulink calculations.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

제품

릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by