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!

 Akzeptierte Antwort

Alexandros Papadopoulos
Alexandros Papadopoulos am 8 Mär. 2019

0 Stimmen

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.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by