Clear Filters
Clear Filters

How to get 'gcb' information including a 'for each' index

3 views (last 30 days)
Hi All
I have a function that has a property 'sParInstanceName'. This variable is updated on starting with the callback function 'InitFcn'.
set_param(gcb,"sParInstanceName",gcb);
This works 'almost' fine. It gets me the path within the model, but it doesn't show the 'index' of the 'for each' block. I don't want to copy the 'index' down via an inport, as this function is the lowest function in about 4 levels of subsystems. It would mean I have to add this additional inport to ALL blocks. Is there maybe an other way of adding this 'index' to the information gathered from the 'gcb' command?
I would like to have this feature, as I have 46 instances of this function and this would help in my debugging. Thanks for any replies.
Ludo

Answers (1)

Fangjun Jiang
Fangjun Jiang on 4 Jan 2024
Edited: Fangjun Jiang on 4 Jan 2024
The "InitFcn" runs only once before each simulation. Whatever info got set to the block is static. The "index" of the "for each" block is dynamic. So I don't think you can achieve what you want by setting dynamic info to a static field of a block property or parameter.
If you have to know the "index" of the "for each" block for debugging purpose, there are two ways.
  1. The "For Each" block can output the value of the for each iterator. You can wire it to the place you wanted or observe it at the output of the "For Each" block.
  2. Add a masked parameter to the "For Each Subsystem". Specify the value of the parameter as [1:N] outside of the "For Each Subsystem". Through parameter patition, you will get the "index" of the "for each" block anywhere inside the "For Each Subsystem" without the need of wiring.
  2 Comments
Ludo Houben
Ludo Houben on 15 Jan 2024
Hi Fangjun Jiang
Thanks for your reply, but this is the already mentioned 'copy the information down' way of working that I prefere not to implement (however good that you mention this). Within C++ and PLC this information is already available at compile time. I was expecting that MATLAB would at least give an indication in the 'gcb' path that there is a 'for each' part available, but this is also not available. I could update the mentioned property also dynamically, but I need a reference as there are 4 layers of subsystems between the 'for each' and the actual function handling the information.
Regards
Ludo
Fangjun Jiang
Fangjun Jiang on 15 Jan 2024
Use approach 2 then. Define and partition a parameter. This parameter can be used anywhere inside the for-each subsystem.

Sign in to comment.

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!