why "if loop" contents not getting computed?

1 次查看(过去 30 天)
clc
clear all
Pc=620*10^6
Pa=62*10^9
Ps=1*10^9
r=10
d0=0.4
d=[10 20 30 40 50 60 70 80 90 100]
s=(d./r)
k1=1
k2=(s+2)./4
k3=s./4
s1=s
w1=4.3
E0=8.85*10^-12
Eb=6.830890.*(w1.^(3/2))
B1=(d./d0).^(1/3)
l=(Eb./B1)
m= (2.*Pc./E0).^(1/2)
n=(8.*Pa./(E0.*(1+s).^4)).^(1/2)
x1=min(m,n)
Es=min(x1,l)
l1= 0.5.*E0.*l.^2.*10^18
n1=(4.*Pa)./((1+(s)).^4)
y1=min(l1,Pa)
y2=min(y1,n1)
if s1<2
e1=k1
elseif s1>=2
e1=k2
else s1>2
e1=k3
end

采纳的回答

Joseph Cheng
Joseph Cheng 2014-3-27
if statements do not work this way. how it is written is if all of s1 is <2. I would suggest read the document on if statements and write a for loop or something like this.
e1(s1<2) = k1; %which says for the index positions where s1 < 2 substitute k1 into e1.
i do not understand what you are doing with s1>2. or should the second nested if statement be s1==2?
  1 个评论
an
an 2014-3-28
I want if statement to be like this if s1<2 ,e1=1 s1=2 ,e1=(s+2)/4 s1>2, e1=s/4

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by