www.pudn.com > matlab&c(1).rar > testif.m


%testif.m 
%if语句的使用方法测试 
function []=showInputSign_if(input) 
%根据输入数据的正负不同,给出不同的输出 
nlen = length(input); 
if nlen>1 
disp('输入数据的不是1x1的数值阵列!');	 
else 
	if input ~= 0 %注意"~="表示"不等于" 
			if input > 0  
				disp('输入数据大于0');	 
			else 
				disp('输入数据小于0'); 
			end			 
		else 
			disp('输入数据等于0');		 
		end 
end 
 
%switch语句的使用方法测试 
function []=showInputSign_switch(input) 
%根据输入数据的正负不同,给出不同的输出 
nlen = length(input); 
if nlen>1 
		disp('输入数据的不是1x1的数值阵列!');	 
else 
		signinput = sign(input); 
    switch signinput 
        case 0 
            disp('输入数据等于0'); 
        case 1 
            disp('输入数据大于0'); 
        case -1 
            disp('输入数据小于0'); 
        otherwise 
            disp('这是不可能的!!!!!!!'); 
    end     
end