Problem with variable-size signals (Simulink)

조회 수: 8 (최근 30일)
Alessandro Persico
Alessandro Persico 2022년 2월 23일
댓글: Alessandro Persico 2022년 2월 25일
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 :)

답변 (1개)

Mark McBroom
Mark McBroom 2022년 2월 25일
  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
Alessandro Persico
Alessandro Persico 2022년 2월 25일
  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....

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by