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)
Show older comments
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
- Put a parameter in the mask for example "filename" and then let the "to workspace" block takes "filename" as the variable name
- 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?
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!