How to dynamically generate a variable name based on the instance of a masked subsystem within a library block in Simulink?

9 views (last 30 days)
I tried to form a line model for my grid simulation and record some simulation results (current and power) at the same time. So this model is in my lib file. The easy way will be I take the recorded results into a bus output. And then when I initianize the instances in the simulink, I take a new bus element out node to save the results. But it will make the grid looks more caos because of so many nodes. I am thinking is it possible to
  1. Put a parameter in the mask for example "filename" and then let the "to workspace" block takes "filename" as the variable name
  2. Let model dynamically generate a variable name based on the instance in the simulink so it can filename1, filename2.. while I intiate the instances in the simulink.
The first method, I tried it, didn't work because the "to workspace" block takes "filename" not as a parameter but a constant string. So I want to know is it possible to realize what I want to do?

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 9 Jan 2024
Edited: Fangjun Jiang on 10 Jan 2024
That is right. Passing a string name through mask is difficult if not impossible.
But what you really need is to log signals and be able to uniquely identify them even though they are inside duplicated library instances. Time to use Simulink Data Inpsector (SDI), either manually or through API. Every block has its unique full path so do its signals.
  2 Comments
Zhao
Zhao on 9 Jan 2024
Edited: Zhao on 9 Jan 2024
Thanks for your answer. But I think it has the same problem as I stated at the question "And then when I initianize the instances in the simulink, I take a new bus element out node to save the results." I want to hide the output port so that user can only see the grid connection and can choose record data yes/no in the window. Is it another way? Or do I understand you wrong?
Fangjun Jiang
Fangjun Jiang on 10 Jan 2024
Take a look at SDI. It is a better way to log signal.
There is no need (or it shouldn't) to add blocks just for the need of signal logging.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!