How to get the port types and dimensions for a block
56 ビュー (過去 30 日間)
古いコメントを表示
We are generating code using RTW via a script. I am trying to collect the port dimensions and data types. Argument names would be great too, but not required.
I am currently able to get the port names
0 件のコメント
採用された回答
Fangjun Jiang
2011 年 6 月 3 日
Sometimes it is hard to find help in the document. Many times I just poke around and make an educated guess. I made a simple model and ran the code below. It seems to be able to get the dimension and data types. Hope this will help.
clc;
acModelName=bdroot;
lcInportHandles = find_system(acModelName,'FindAll','On','SearchDepth',1,'BlockType','Inport');
for i=1:length(lcInportHandles)
lcInputDimensions = get_param(lcInportHandles(i),'CompiledPortDimensions');
lcInputDimensions=lcInputDimensions.Outport
lcInputDataTypes = get_param(lcInportHandles(i),'CompiledPortDataTypes');
lcInputDataTypes = lcInputDataTypes.Outport
end
The output looks like this:
lcInputDimensions =
1 2
lcInputDataTypes =
'single'
lcInputDimensions =
1 1
lcInputDataTypes =
'int8'
その他の回答 (4 件)
Nirmal Gunaseelan
2011 年 6 月 2 日
You can get the dimensions and data types of a block's port after you put the model into a 'compiled' state. The
model([],[],[],'compile')
where model is your model name will get you there. After that, a get_param on the block of interest with the options
CompiledPortDimensions
CompiledPortDataTypes
will get you the info you want.
3 件のコメント
Nirmal Gunaseelan
2011 年 6 月 3 日
'model' in the above snippet is the name of your loaded model. I like to think of it as a way to interact with the model as though it has a function signature.
I have been using this snippet for a long time now, I believe it was there as far back as R14.
Fangjun Jiang
2011 年 6 月 2 日
Some properties such as dimensions and data types are not up to date when the model is loaded. These properties depend on other information. They also need to be cross-checked to avoid any miss-match. You need to "update" the model or further force the model to be "compiled" to go through those propagation and cross-checking. The command model([],[],[],'compile') is to force that process. model is not a handle. It is the name of your model. The model needs to be loaded. Once the command model([],[],[],'compile') is done. You can use find_system() with 'SearchDepth' to find all the root-level Inport blocks and Output blocks. And then you can get the dimension and data type property of all those Inport/Outport blocks.
Kevin
2011 年 6 月 2 日
3 件のコメント
Fabien Jeanneteau Safran
2022 年 5 月 11 日
Hi,
If you are stuck (like me), you should try:
model([],[],[],'term')
I found answer on following page: https://fr.mathworks.com/matlabcentral/answers/29764-turn-off-compile-mode
Regards,
Fabien
参考
カテゴリ
Help Center および File Exchange で Programmatic Model Editing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!