函数内的MATLAB函数和带strcmp的if语句

时间:2015-02-17 05:00:14

标签: matlab function if-statement

我的代码似乎总是给我带来新的错误。通过调试,我意识到错误是由if语句在哪里指定' b'。有时,当代码运行时,它只返回所有输入的一个奇异值。

它还会随机询问结束语句,并且不接受elseif语句。我真的需要知道究竟是什么搞乱了。

请帮助!

x = inputdlg({'Pathogen','Month (First letter capital)', 'Population Renewal', 'Death Rate'}, 'Inputs - Please enter the following information');
g = getfield(x,{1});
f = getfield(x,{2});
if strcmp('g','Salmonella')
    if any (strcmp(f,{'November','December','January','February','March','April'}))
%if ismember (f,{'January','February'})
    b = 0.01
elseif any (strcmp(f,{'May','June','July','August'}))
    b = 0.0001
    else 
        b = 0.001
    end
end

%b = str2double(x{1});
p = str2double(x(3));
l = 0.5;
d = 0.9;
m = str2double(x(4));
f = (b*p)*(1+(l*d)); 
h = m*(m+l);
R = f/h;

if (R<1)
answer = msgbox(['Value = ' num2str(R) ' therefore there is no epidemic'],'Basic Reproduction number')
else
    answer = msgbox(['Value = ' num2str(R) ' therefore there is an epidemic'],'Basic Reproduction number')
end


yo = [20 5 5 10]; 
[t x]= prmgr(p,m,yo);
plot(t,x(:,1),'k','Linewidth',1.5)
hold
[t y] = msifunc(b,p,m,l,d,yo);
plot(t,y(:,1),'-r*','Linewidth',1.5,'MarkerSize',5)
title('Susceptible Population')
legend('Disease free state','Test state')



if strcmp('g','Shigella')   
if any (strcmp(f,{'November','December','January','February','March'}))
%if ismember (f,{'January','February'})
    b = 0.01
elseif any (strcmp(f,{'May','April','October'}))
    b = 0.001
    else 
        b = 0.00001
end

end
%b = str2double(x{1});
p = str2double(x(3));
n = 0.14;
m = str2double(x(4));
f = b*p; 
h = m*(m+n);
R = f/h;

if (R<1)
answer = msgbox(['Value = ' num2str(R) ' therefore there is no epidemic'],'Basic Reproduction number')
else
    answer = msgbox(['Value = ' num2str(R) ' therefore there is an epidemic'],'Basic Reproduction number')
end

yo = [20 5 10]; 
[t u] = ugr(p,m,yo);
plot(t,u(:,1),'k','Linewidth',1.5)
hold
[t v] = shigfunc(b,p,m,yo)
plot(t,v(:,1),'-r*','Linewidth',1.5,'MarkerSize',5)
title('Susceptible Population')
legend('Disease free state','Test state')


if strcmp('g','Rotavirus')
    if any (strcmp(f,{'May','June','July','August'}))
    b = 0.1
elseif any (strcmp(f,{'October','March'}))
    b = 0.001
    else 
        b = 0.01
    end
end

%b = str2double(x{1});
p = str2double(x(3));
l = 0.5;
d = 0.9;
q = 0.4
m = str2double(x(4));
f = (b*p*q); 
h = m*(m+l);
R = f/h;

if (R<1)
answer = msgbox(['Value = ' num2str(R) ' therefore there is no epidemic'],'Basic Reproduction number')
else
    answer = msgbox(['Value = ' num2str(R) ' therefore there is an epidemic'],'Basic Reproduction number')
end


yo = [20 5 5 10]; 
[t w]= rota(p,m,yo);
plot(t,w(:,1),'k','Linewidth',1.5)
hold
[t z] = rotfunc(b,p,m,l,d,yo);
plot(t,z(:,1),'-r*','Linewidth',1.5,'MarkerSize',5)
title('Susceptible Population')
legend('Disease free state','Test state')

0 个答案:

没有答案