求matlab中的switch模块的用法? 5

 我来答
lhmhz
高粉答主

推荐于2016-09-29 · 专注matlab等在各领域中的应用。
lhmhz
采纳数:7264 获赞数:17008

向TA提问 私信TA
展开全部

switch模块是simulink公共模块库的一个基本模块,switch模块也可以理解开关模块。其功能是输入1时,输入2,满足选定的标准,否则,通过输入3。输入编号为底部(或左至右)。输入1通过标准输入2大于或等于,大于或不等于阈值。第一和第三个输入端口是数据端口,其次是控制端口的二次输入端口。

调用方法:

1、在指令窗口下,输入simulink,打开simulink模型库

2、点击Commonly Used Blocks,选择switch后Ctrl+I,新建命令文件

选择switch图标,右击,这样就可以设置开关值

I_Swing
2011-04-15
知道答主
回答量:14
采纳率:0%
帮助的人:12.7万
展开全部
switch 表达式
case 值1
语句1
case 值2
语句2
.......
otherwise
语句n
end
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lifemyself1
2011-04-11 · 超过13用户采纳过TA的回答
知道答主
回答量:46
采纳率:0%
帮助的人:0
展开全部
switch

Switch among several cases, based on expression
Syntax

switch switch_expr
case case_expr
statement, ..., statement
case {case_expr1, case_expr2, case_expr3, ...}
statement, ..., statement
otherwise
statement, ..., statement
end

Discussion

The switch statement syntax is a means of conditionally executing code. In particular, switch executes one set of statements selected from an arbitrary number of alternatives. Each alternative is called a case, and consists of

*

The case statement
*

One or more case expressions
*

One or more statements

In its basic syntax, switch executes the statements associated with the first case where switch_expr == case_expr. When the case expression is a cell array (as in the second case above), switch executes the case where any of the elements of the cell array matches the switch expression. If no case expression matches the switch expression, then control passes to the otherwise case (if it exists). After the case is executed, program execution resumes with the statement after the end.

The switch_expr can be a scalar or a string. A scalar switch_expr matches a case_expr if switch_expr==case_expr. A string switch_expr matches a case_expr if strcmp(switch_expr,case-expr) returns logical 1 (true).

A case_expr can include arithmetic or logical operators, but not relational operators such as < or >. To test for inequality, use if-elseif statements.

Note for C Programmers Unlike the C language switch construct, the MATLAB switch does not "fall through." That is, switch executes only the first matching case; subsequent matching cases do not execute. Therefore, break statements are not used.

Examples

To execute a certain block of code based on what the string, method, is set to,

method = 'Bilinear';

switch lower(method)
case {'linear','bilinear'}
disp('Method is linear')
case 'cubic'
disp('Method is cubic')
case 'nearest'
disp('Method is nearest')
otherwise
disp('Unknown method.')
end

Method is linear

See Also

case, otherwise, end, if, else, elseif, while

参考资料: matlab help

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式