Automate looping through different submodules with Matlab / Blockset

Hello everybody.

Trying to cycle through a number of different circuit configuration, I stumbled across this issue:

  • Is it possible to change the configuration of a PLECS model submodule automatically using Matlab?

I have:

  • A simulation model that takes variables for parameters and has different circuits, implemented as configurable submodules

  • Matlab scripts to loop through one configuration for a parameter range

However, when I want to change the configuration of the submodule (switch to another circuit), I could not find an automatic way to do so (currently, I manually change the config in the drop down menu, see attached screenshot).

Any way to do so? Would be a great help for automation!

Hello,

I recommend that you use a reference variable for the subsystem configuration selection parameter. You can then write a value to that variable from your script, where 1 equals the first configuration from left-to-right, 2 equals the second in order, etc.

Try this out and let me know if you are successful.

Regards,

Kris

Hey Kris.

Thanks for the quick reply. I already use this method to change values of circuit elements. However, I could not find a way to set a variable for the subsystem configuration. Is there any context menu I am missing?

Thanks and best regards!

Hello,

You will need to choose the ‘reference’ option for the Configuration parameter and overwrite this with a variable name that you can then write to from your script. See the simple example attached. You can include the following text in a .m file script or type it directly into the MATLAB command line to toggle between the two subsystem configurations:

configuration = 1;


configuration = 2;

I also attached an example in PLECS Standalone for anyone else in the future that has this questions. Let me know if you have any issues.Regards,Kris

configurable_subsystem_by_reference.plecs (9.28 KB)

configurable_subsystem_by_reference.slx (23.3 KB)