필터 지우기
필터 지우기

How to add three if else conditions?

조회 수: 47 (최근 30일)
Shantanu K
Shantanu K 2013년 3월 12일
Here one if else loop is used. there i have used three conditions i want to use and operator.....means if all conditions are satisfied then it should display given function !
Sigma_x=-500;
Sigma_y=-500;
Sigma_xy=00;
theta=0;
o=(pi)*theta/180;
T=[cos(o) -sin(o); -sin(o) cos(0)];
Q= T*[Sigma_x Sigma_xy; Sigma_xy Sigma_y]/(T');
Sigma1=Q(1,1);
Sigma12=Q(1,2);
Sigma2=Q(2,2);
S1t=1300;
S1c=-700;
S2t=1200;
S2c=-500;
S6=600;
S1=(S1c:S1t);
S2=(S2c:S2t);
plot(S1t,S2);
hold on;
plot(S1c,S2);
hold on;
plot(S1,S2t);
hold on;
plot(S1,S2c);
plot(Sigma1,Sigma2,'*')
axis([-800 1600 -800 1600])
xlabel('Sigma1')
ylabel('Sigma2')
title('Maximum Stress Theory')
if (S1c<Sigma1<S1t);
and
(S2c<Sigma2<S2t);
and
(0<Sigma12<S6);
display('Its safe zone');
else
display('Material has yielded');
end
%end

채택된 답변

Friedrich
Friedrich 2013년 3월 12일
편집: Friedrich 2013년 3월 12일
Hi,
do it like this
if ((S1c<Sigma1) && (Sigma1<S1t) && (S2c<Sigma2) && (Sigma2<S2t) && (0<Sigma12) && (Sigma12<S6))
display('Its safe zone');
else
display('Material has yielded');
end
You have to split up things like a<b<c into a<b && b<c otherwise you can get unwanted behavior, e.g.
>> 1<2<3 %yay it works
ans =
1
>> 1<pi<3 %oh wait it doesnt!
ans =
1
This happens because of the way MATLAB parses such an expression. It parses from left to right, so 1<pi is true, so 1. Then 1 < 3 is also true so you get true at the end. But thats not want you want

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by