Reputation: 45
For Example: From attached Simulink model figure (This model has no meaning. created only to give idea about my problem ), I want to get the order of blocks based on pin connection instead of their alphabetic order.
The order should be like (Expected Output):
Integrator,Second-Order Limited Block
Integrator or Rate Limiter Dynamic Block
Rate Limiter Dynamic or Integrator Block
Lookup table Dynamic Block
Data type Conversion block
n-DLookup Table Block
But Currently I am getting order based on Aplhabatic name of Blocks (Refer below image for the results uisng 'find_system' command.)
Upvotes: 3
Views: 1089
Reputation: 10762
There isn't a function that will do this automatically for you - you'll need to write your own.
It looks like you are positioning based on block position (from left to right). In that case, you want something like the following (using the demo f14
model):
>> open_system('f14')
>> blocks = find_system(gcs,'SearchDepth',1,'Type','Block');
>> positions = get_param(blocks,'Position');
>> leftPos = cellfun(@(c)c(1),positions);
>> [~,newOrderIdx] = sort(leftPos);
>> blocks(newOrderIdx)
ans =
18×1 cell array
'f14/Pilot'
'f14/u'
'f14/Controller'
'f14/Sum1'
'f14/Dryden Wind…'
'f14/Stick Input'
'f14/Gain'
'f14/Gain1'
'f14/Gain2'
'f14/Actuator…'
'f14/Sum'
'f14/Aircraft…'
'f14/Nz pilot…'
'f14/Gain5'
'f14/Angle of …'
'f14/Pilot G force…'
'f14/Nz Pilot (g)'
'f14/alpha (rad)'
Upvotes: 2