Clear Filters
Clear Filters

如何不使用Multi​meter模块通过脚​本获取Simulin​k模块内部的测量数据​?

12 views (last 30 days)
珊
on 4 Jan 2024
Answered: Yash on 12 Jan 2024
我在Simulink中进行电力系统模拟时遇到了一个问题。在我的模型中,我有一个三相短路模块,该模块内部可以测量诸如短路电流之类的参数。通常,如果需要记录和分析测量数据,我们会在Simulink模型的信号线上手动点击右键选择“记录信号”。然而,我希望能够通过编写MATLAB脚本来自动化这一过程,并且我不想在模型中额外添加Multimeter模块来实现这一点。
请问有没有办法在不添加Multimeter模块的情况下,通过脚本直接访问和记录Simulink模块内部的这些测量数据?我知道这可能需要使用Simulink API和数据日志记录功能,但是不确定具体的实施步骤。如果有人能提供指导或相应的代码示例,将不胜感激。
谢谢大家!

Answers (1)

Yash
Yash on 12 Jan 2024
Hi ,
The following commands can be used to automate the processing of logging a signal without using the "Multimeter" block:
% open the Simulink model (using the example model "power_compensated" here)
open_system('power_compensated');
% Add a 'To Workspace' block to the Simulink model
toWorkspaceBlock = add_block('simulink/Sinks/To Workspace', 'power_compensated/To Workspace');
% Set the variable name for the signal to be logged and its save format
set_param(toWorkspaceBlock, 'VariableName', 'logged_signal');
set_param(toWorkspaceBlock, 'SaveFormat', 'Array');
% Connect the block with its port number to "To Workspace" block for the
% signal you want to log (Demux port number 1 signal in this case)
add_line('power_compensated', 'Demux/1', 'To Workspace/1');
% Run the simulation and the logged signal will be saved to the workspace
sim('power_compensated');
Refer here for more information on the "power_compensated" example model and “To Workspace” block:

Categories

Find more on 编程式模型编辑 in Help Center and File Exchange

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!