How to pass multiple (>50) variables between blocks in Simulink

조회 수: 28 (최근 30일)
Karol P.
Karol P. 2023년 10월 31일
편집: Ayush 2023년 12월 5일
I'm looking for a method to pass multiple variables of different type (double, vector, string etc.) between blocks in Simulink. If I have several, I can pass it separately, or even better pack to structure like (for example if I pass it from Function block):
var_holder=struct('VarA',VarA,'VarB',VarB,'VarC',VarC);
And set manually a Bus to pass it to next block. However what can I do if I work with very big model, where I have to solve over 50 ODEs, and pass the result to the next step? Setting manually this endless Bus does not sounds like correct way to do so. What is recommended way to work with multivariable Simulink models?
  댓글 수: 1
Sayan
Sayan 2023년 12월 4일
편집: Sayan 2023년 12월 4일
If you are asking about taking 50 outputs and use them in different blocks ,you can use the MATLAB function block to output 50 variables and demux it to use further in othr blocks.Does this answer the query?

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

답변 (1개)

Ayush
Ayush 2023년 12월 5일
편집: Ayush 2023년 12월 5일
I understand that you want to pass multiple variables of different type (double, vector, string etc.) between blocks in Simulink without relying upon buses. You can use Parameter Structures to pass multiple variables of different types.
Define a structure in MATLAB workspace containing all the variables and use Simulink.Parameter objects to link to the structure fields.
% Define a Simulink.Parameter in the MATLAB workspace
myParam = Simulink.Parameter;
myParam.Value = 10;
If the next block in your Simulink model accepts Simulink.Parameter objects directly, you can connect the Simulink.Parameter directly to the input of that block.
% Create a new Simulink model or open an existing one
open_system('myModel');
% Add a block to the Simulink model that accepts Simulink.Parameter objects
% For example, if the block is a Gain block, you can directly connect myParam to it
add_block('simulink/Commonly Used Blocks/Gain', 'myModel/GainBlock');
% Connect the Simulink.Parameter to the input of the block
set_param('myModel/GainBlock', 'Gain', 'myParam');
You can also use Data Store Memory Block:
  • Place a Data Store Memory block in your Simulink model. Double-click the block and enter the name of the Simulink.Parameter in the "Data store name" field.
  • Connect the Data Store Memory block to the input of the next block in your Simulink model.
For more information on:
  1. Simulink.Parameter refer: https://www.mathworks.com/help/simulink/slref/simulink.parameter.html
  2. Data Store Memory: https://www.mathworks.com/help/simulink/slref/datastorememory.html
Thank you

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by