why "if loop" contents not getting computed?

1 view (last 30 days)
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

Accepted Answer

Joseph Cheng
Joseph Cheng on 27 Mar 2014
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 Comment
an
an on 28 Mar 2014
I want if statement to be like this if s1<2 ,e1=1 s1=2 ,e1=(s+2)/4 s1>2, e1=s/4

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!