| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4537 人关注过本帖
标题:[求助]简单的 switch、case语句,总是不能判断条件??
只看楼主 加入收藏
t_vc
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-4-7
收藏
 问题点数:0 回复次数:6 
[求助]简单的 switch、case语句,总是不能判断条件??

简单的Switch、case语句,总是不能判断条件

clear;clc;
s=input('请输入数字');
switch s
case s==10
r='十环';
case s<10&s>=0
r='不好';
otherwise
r='不可能';
end,s,r


当我运行,并且输入10,给出结果:不可能 ,请教各位,哪里写错了?

[此贴子已经被作者于2006-4-23 19:21:06编辑过]

搜索更多相关主题的帖子: case语句 switch 条件 判断 clc 
2006-04-23 19:20
Genial
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:175
专家分:0
注 册:2006-3-31
收藏
得分:0 
input得到的是字符
2006-04-24 00:13
t_vc
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-4-7
收藏
得分:0 
那怎么才能得到数字?

2006-04-24 17:28
XW_BAI
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-4-27
收藏
得分:0 
swith case 用的不对
看help switch
2006-04-28 08:43
XW_BAI
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-4-27
收藏
得分:0 
clear
clc
prompt={'请输入环数'};
def={'10'};
dlgTitle='打靶评价';
lineNo=1;
tem=inputdlg(prompt,dlgTitle,lineNo,def);
s=str2num(tem{1});
if s==10
disp('十环')
elseif s>0 & s<10
disp('不太好')
else
disp('不可能')
end
2006-04-28 08:47
sagiltarivs
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-5-12
收藏
得分:0 
看来没有学过C啊,switch是不能当if的理解去用的,尽管可以和if等价
给出switch版本,但是可以明显的看到switch语句用在此场合下没有if语句好
记得要用break;
clear;clc;
s=input('请输入数字');
switch s
case 0,
case 1,
case 2,
case 3,
case 4,
case 5,
case 6,
case 7,
case 8,
case 9,
r='不好';
break;
case 10
r='十环';
break;
otherwise
r='不可能';
end,s,r

2006-05-12 21:48
sagiltarivs
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-5-12
收藏
得分:0 
[QUOTE]input得到的是字符[/QUOTE]
首先应该查看input的help而不是信口开河
INPUT Prompt for user input.
R = INPUT('How many apples') gives the user the prompt in the
text string and then waits for input from the keyboard.
The input can be any MATLAB expression, which is evaluated,
using the variables in the current workspace, and the result
returned in R. If the user presses the return key without
entering anything, INPUT returns an empty matrix.

R = INPUT('What is your name','s') gives the prompt in the text
string and waits for character string input. The typed input
is not evaluated; the characters are simply returned as a
MATLAB string.

The text string for the prompt may contain one or more '\n'.
The '\n' means skip to the beginning of the next line. This
allows the prompt string to span several lines. To output
just a '\' use '\\'.

See also KEYBOARD.
默认情况下input返回的是double的matrix
如果要返回string类型,可以用
s = input('input your option','s');

2006-05-12 21:57
快速回复:[求助]简单的 switch、case语句,总是不能判断条件??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012168 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved