Programmatically get propagated datatype of a block

2 views (last 30 days)
I am trying to get a block propogated datatype when the output datatype is selected to inherit. I know we can use get_param to get datatype setting but I am interested in getting datatype a block outputs post update model (Ctrl+D).
I have a model with fixed point datatypes where some of the blocks are inheriting the datatype. I want to pin-point which block is using a perticular word length post propogation.

Accepted Answer

Andy Bartlett
Andy Bartlett on 5 Jul 2022
Hi,
The attached function provides an example of how to use Simulink API's to get data type information from signals and run-time parameters.
This can be run like so.
mdl = 'fxpdemo_feedback';
open_system(mdl);
[cellDts,cellDtStrs,rootOutCellDts,rootOutCellDtStrs,S] = find_all_dt_io(mdl)
You can see the list of data types detected as numerictype objects or as strings. Here is an example of seeing the string names used by Simulink.
S.cellDtStrs
ans =
1×5 cell array
{'double'} {'sfix16_En14'} {'sfix16_En5'} {'sfix32_En12'} {'sfix8_En4'}
To see where a particular data type was detected, you can use the data type name as a field name for the last function output argument.
S.sfix16_En14
ans =
struct with fields:
ntStrML: 'numerictype(1,16,14)'
ntStrSL: 'fixdt(1,16,14)'
nt: [1×1 embedded.numerictype]
RtParam: {1×2 cell}
Inport: {'fxpdemo_feedback/Controller/Numerator Terms'}
Outport: {'fxpdemo_feedback/Controller/Up Cast'}
That data type was used as an input to one block and the output from another block.
The data type was also used with Run-Time parameters of two blocks.
S.sfix16_En14.RtParam
ans =
1×2 cell array
{'fxpdemo_feedback/Controller/Denominator…'} {'fxpdemo_feedback/Controller/Numerator T…'}
You can look inside
edit find_all_dt_io
to see what it's doing. It's using the techniques that Fangjun Jiang mentioned. Plus, getting the Run-Time Parameter information.
Regards,
Andy

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 4 Jul 2022
Something like
model([], [], [], 'compile')
get_param('BlockPath','CompiledDataType')
model([], [], [], 'term')
You can use this to get all the compiled data types and then search for a paticular data type string.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!