How can I specify the output of a Matlab Function Block to be of a specific Bus type programatically?

조회 수: 16 (최근 30일)
I have a matlab function block that has several inputs, and combines them into a structure that matches a Simulink bus object on the workspace. From the editor GUI, , clicking on the edit data button or through the explorer, I can set the output Data Type to be of Bus: MyBusType, rather than inherited. But, I need to be able to do this programmatically. Is there a way? If I get the PortHandles for the block, and then get_param the signal hierarchy for that port, I can see that I set it to the MyBusType, but this is a read only parameter so set_param can not work.

채택된 답변

Dimitris Iliou
Dimitris Iliou 2016년 10월 14일
If I understand correctly, you want to be able to change the output Datatype for the MATLAB Function Block programmatically instead doing it through the GUI.
In order to do that you need to work with the Stateflow API because the MATLAB Function Block uses it.
So what you would need to do is find the Stateflow root object, then the MATLAB Function Block, and finally locate and change the necessary output.
This can be done with the following snippet of code below:
% Find stateflow root object
rt = sfroot;
% Find the MATLAB Function block
A = rt.find('-isa','Stateflow.EMChart');
% Find the outputs
A.outputs;
% If you want to view the 1st output
A.outputs(1);
% Change the data type using the 'DataType' property
A.outputs(1).DataType = 'double';
If you have multiple MATLAB Function Blocks,‘A’ will be a struct and you would need to find the element that corresponds to the MATLAB Function Block you want to change. Also, A.outputs contains all the outputs of the specific block so you would also need to locate the correct output to edit.
  댓글 수: 2
Chris Bogath
Chris Bogath 2016년 10월 15일
Thank you! I was already using the Stateflow API to set the script, just didn't realise the outputs DataType property. Works perfectly.
Nikita Visnevski
Nikita Visnevski 2021년 2월 20일
Is Stateflow license required to perform this? I cannot tell easily as I have Stateflow license, but I am writing code that others without Stateflow license may need to execute.
If Stateflow license is required, does anyone know of a way to do the same action without relying on Stateflow API?

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

추가 답변 (1개)

Igal
Igal 2018년 6월 19일
Is there any way I can set bus size programatically, the way Data Type is set in the answer above? I can't find it anywhere in documentation.
Thanks.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by