How to get 'gcb' information including a 'for each' index
Mostra commenti meno recenti
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
Risposte (1)
Fangjun Jiang
il 4 Gen 2024
Modificato: Fangjun Jiang
il 4 Gen 2024
0 voti
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.
- 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.
- 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 Commenti
Ludo Houben
il 15 Gen 2024
Fangjun Jiang
il 15 Gen 2024
Use approach 2 then. Define and partition a parameter. This parameter can be used anywhere inside the for-each subsystem.
Categorie
Scopri di più su Model, Block, and Port Callbacks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!