simulink+单刀单掷开关
时间: 2023-12-12 11:34:10 浏览: 180
在Simulink中,单刀单掷开关可以用于控制信号的开关。可以使用Switch模块来实现单刀单掷开关的功能。下面是一个简单的例子:
1.首先,从Simulink库中拖动Switch模块到模型中。
2.将需要控制的信号连接到Switch模块的输入端口。
3.将Switch模块的控制输入端口连接到单刀单掷开关的输出端口。
4.运行模型,通过单刀单掷开关控制信号的开关。
```matlab
% Simulink单刀单掷开关示例模型
% 该模型使用Switch模块实现单刀单掷开关的功能
% 定义输入信号
t = 0:0.01:10;
u = sin(t);
% 定义单刀单掷开关信号
sw = [zeros(1, 500) ones(1, 501)];
% Simulink模型
mdl = 'switch_example';
open_system(mdl);
add_block('simulink/Sources/Sine Wave', [mdl '/Sine Wave']);
add_block('simulink/Commonly Used Blocks/Switch', [mdl '/Switch']);
add_block('simulink/Sinks/Scope', [mdl '/Scope']);
set_param([mdl '/Sine Wave'], 'Position', [50, 50, 100, 100]);
set_param([mdl '/Switch'], 'Position', [200, 50, 250, 100]);
set_param([mdl '/Scope'], 'Position', [350, 50, 400, 100]);
connect_param(mdl, 'Sine Wave/1', 'Switch/1');
connect_param(mdl, 'Switch/1', 'Scope/1');
set_param([mdl '/Switch'], 'Criteria', 'u2 ~= 0');
set_param([mdl '/Switch'], 'Threshold', '0.5');
set_param([mdl '/Switch'], 'TimeOn', '0.1');
set_param([mdl '/Switch'], 'TimeOff', '0.1');
set_param([mdl '/Switch'], 'InitialCondition', '0');
set_param([mdl '/Switch'], 'Inputs', '2');
set_param([mdl '/Switch'], 'Position', [200, 50, 250, 100]);
set_param([mdl '/Switch'], 'ShowName', 'off');
set_param([mdl '/Switch'], 'ShowIcon', 'on');
set_param([mdl '/Switch'], 'IconDisplay', 'Switch');
set_param([mdl '/Switch'], 'IconShape', 'rectangle');
set_param([mdl '/Switch'], 'IconFillColor', 'white');
set_param([mdl '/Switch'], 'IconLineColor', 'black');
set_param([mdl '/Switch'], 'IconLineWidth', '1');
set_param([mdl '/Switch'], 'IconWidth', '15');
set_param([mdl '/Switch'], 'IconHeight', '15');
set_param([mdl '/Switch'], 'IconRotation', '0');
set_param([mdl '/Switch'], 'IconFlip', 'none');
set_param([mdl '/Switch'], 'IconOpacity', '1');
set_param([mdl '/Switch'], 'IconShapeComputation', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunction', '');
set_param([mdl '/Switch'], 'IconShapeFunctionArgs', '');
set_param([mdl '/Switch'], 'IconShapeFunctionOutput', '');
set_param([mdl '/Switch'], 'IconShapeFunctionWorkspace', '');
set_param([mdl '/Switch'], 'IconShapeFunctionSampleTime', '-1');
set_param([mdl '/Switch'], 'IconShapeFunctionDiscreteState', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionInheritedSampleTime', 'Inherit');
set_param([mdl '/Switch'], 'IconShapeFunctionOutputSampleTime', '-1');
set_param([mdl '/Switch'], 'IconShapeFunctionStateName', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateType', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensions', '-1');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsMode', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustom', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValue', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValueEdit', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePrompt', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptTitle', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptText', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptDefault', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptType', 'string');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptMask', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptCallback', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptApply', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptCancel', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptHelp', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptPosition', 'center');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptUnits', 'pixels');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptResize', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptWindowStyle', 'normal');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreter', 'tex');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterMode', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustom', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValue', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValueEdit', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePrompt', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptTitle', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptText', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptDefault', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptType', 'string');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptMask', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptCallback', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptApply', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptCancel', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptHelp', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptPosition', 'center');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptUnits', 'pixels');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptResize', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptWindowStyle', 'normal');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreter', 'tex');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterMode', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustom', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValue', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValueEdit', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePrompt', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptTitle', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptText', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptDefault', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptType', 'string');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptMask', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptCallback', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptApply', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptCancel', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptHelp', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptPosition', 'center');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptUnits', 'pixels');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptResize', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptWindowStyle', 'normal');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreter', 'tex');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterMode', 'Auto');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustom', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValue', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValueEdit', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePrompt', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptTitle', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptText', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptDefault', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptType', 'string');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptMask', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptCallback', '');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptApply', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptCancel', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptHelp', 'off');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptPosition', 'center');
set_param([mdl '/Switch'], 'IconShapeFunctionStateDimensionsModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptInterpreterModeCustomValuePromptUnits
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)