필터 지우기
필터 지우기

Multiple if statements with two conditions

조회 수: 26 (최근 30일)
Muhammad Imran
Muhammad Imran 2020년 4월 24일
댓글: Rik 2020년 4월 28일
Hi. I want to know how can i reduce these if statements with two conditions.
I have tried following code but it is very lengthy to use for like 50 values.
X = {'1';'2A';'2B';'3';'4'}'; %Seismic Zone
Z = [0.075, 0.15, 0.2, 0.3, 0.4]'; %Zone factor
zTbl = table(Z,'RowNames',X); %Table of Zone and Zone Factor
x = input('What is seismic zone?: ','s'); %Seismic Zone input
Z = zTbl{upper(x),'Z'} % Z factor assigned
SP=input('What is SP?: ','s')
SP1=upper(SP)
if Z==0.075 & SP1=='SA'
Ca=0.06
elseif Z==0.075 & SP1=='SB'
Ca=0.08
elseif Z==0.15 & SP1=='SA'
Ca=0.16
.
.
end

채택된 답변

Rik
Rik 2020년 4월 24일
Create an array with all implemented values of CA. Then you can use array operations to find the index, which will allow you to easily add cases and detect combinations that aren't implemented.
  댓글 수: 16
Muhammad Imran
Muhammad Imran 2020년 4월 28일
But i have to also take care of the closest disatance input. Where will i compare it?
Rik
Rik 2020년 4월 28일
Like this?
CD1=input('What is closet distance to known source?:');
if CD1<CD(1),CD1=CD(1);elseif CD1>CD(end),CD1=CD(end);end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by