Problem with variable-size signals (Simulink)

6 Ansichten (letzte 30 Tage)
Alessandro Persico
Alessandro Persico am 23 Feb. 2022
Hey guys, I am facing some issues in a Simulink thermal-hydraulic code which deals with variable-size signals. The code is a bit complex but the problems are very easy to understand. They are two:
  1. I want to use a Matlab Function block which calculates the temperature (a single variable) in different nodes. The number of nodes - i.e. the length of variable temperature - is user-defined and fixed during the simulation. How can I define such a variable?
  2. My code needs to select either one Matlab Function block or another according to working conditions (calculated by the code itself in external blocks) to do some calculations. The two Functions have the same outputs - used then by the rest of the code - but with different dimensions (e.g. Matlab Function A calculates temperature in 5 nodes, Matlab Function B calculates temperature in 3 nodes). So, the size of the variable temperature is changing during the simulation. How can I define such a variable?
These are two different cases I need to solve. I tried by defining for a very basic Matlab Function block a variable-size signal using Model Explorer and flagging “Variable size”, but then I get the error “The sample time for any variable-size signal must be discrete” which I am not able to fix.
If you need more info, please let me know.
Thanks guys :)

Antworten (1)

Mark McBroom
Mark McBroom am 25 Feb. 2022
  1. use coder.varsize() in the ML Function block to define the variable temperature as variable length
  2. you should be able to feed the two signals into a switch block similar to what is shown in the example sldemo_varsize_basic. Type "sldemo_varsize_basic" at the MATLAB prompt to see the example.
  1 Kommentar
Alessandro Persico
Alessandro Persico am 25 Feb. 2022
  1. code.varsize() is not useful because my temperature variable is the output of ML Function block, and when I run the simulation Simulink gives me the error “The sample time for any variable-size signal must be discrete”. Please, try to run this very simplified version of the code:
Create a Simulink system like this
with the following ML Function block:
function out = variableSize(flag)
out = ones(flag,1);
end
If you run, Simulink will firstly ask you to check "Variable size" check box in Model Explorer and to indicate the upper bound of the signal (e.g. [20 1]). After that, it will detect another error which says:
How can I change the sample time? I need to run simulations in continuous time, but Simulink asks me to use discrete sample time....

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by