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

5 次查看(过去 30 天)
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?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2024-1-9
编辑:Fangjun Jiang 2024-1-10
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 个评论
Zhao
Zhao 2024-1-9
编辑:Zhao 2024-1-9
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 2024-1-10
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by