필터 지우기
필터 지우기

Issue with multiple If condition

조회 수: 2 (최근 30일)
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 8월 18일
댓글: Jorge Luis Paredes Estacio 2023년 8월 18일
Hello, I have an issue with the if condition.
I have the following values for the case I have the issue
P_matrix=[53.9350, 53.95, 54125];
S_matrix=[-1, 60.485, 60.57];
TS_arrival_lag=5.3257;
TS_checking=0.9*TS_arrival_lag;
This is the code. The part that is bolted was added to identify a specific case with another condition to explore more options in the selection of the results. However, when it goes inside the condition it gets out from the entire condition despite the condition is met. I added break points to find out the issue and it works for the line indicated below which the target result when the condition is met. I would appreciate the help.
%% Analysis of the P- and S-wave arrivals
%Sorted P-wave Matrix
P_matrix=[plocx; plocy; plocz];
P_matrix=sort(P_matrix);
% Sorted S-wave Matrix
S_matrix=[slocx; slocy; slocz];
S_matrix=sort(S_matrix);
% Estimating the variance between whole P-wave matrix and the two consecutive maximum values
Var_P_wave1=var(P_matrix);
Var_P_wave2=var([P_matrix(1,1);P_matrix(2,1)]);
Var_P_wave3=var([P_matrix(2,1);P_matrix(3,1)]);
% Estimating the variance between the whole S-wave matrix and the two consecutive maximum values
Var_S_wave1=var(S_matrix);
Var_S_wave2=var([S_matrix(2,1);S_matrix(3,1)]);
Var_S_wave3=var([S_matrix(1,1);S_matrix(2,1)]);
%% Estimation of the P-wave and S-wave for windowing procedure
if Var_P_wave1<1.5 && Var_S_wave1<1.5
Pt=mean(P_matrix);
St=mean(S_matrix);
elseif Var_P_wave1<1.5 && Var_S_wave1>1.5
if Var_S_wave2<1.5 && mean([S_matrix(2,1);S_matrix(3,1)])>=(mean(P_matrix)+0.5*TS_arrival_lag) && mean([S_matrix(2,1);S_matrix(3,1)])<=(mean(P_matrix)+1.5*TS_arrival_lag)
Pt=mean(P_matrix); ____________ (This works by using break points which it the condition met)
St=mean([S_matrix(2,1);S_matrix(3,1)]); _____________(This works by using break points which is the condition met)
elseif Var_S_wave3<1.5 && mean([S_matrix(1,1);S_matrix(2,1)])>=(mean(P_matrix)+0.5*TS_arrival_lag) && mean([S_matrix(1,1);S_matrix(2,1)])<=(mean(P_matrix)+1.5*TS_arrival_lag)
Pt=mean(P_matrix);
St=mean([S_matrix(1,1);S_matrix(2,1)]);
else
Pt=mean(P_matrix);
St=Pt+ TS_checking;
end
elseif Var_P_wave2<1.5 && Var_S_wave2<1.5
Pt=mean([P_matrix(1,1);P_matrix(2,1)]);
St=mean([S_matrix(2,1);S_matrix(3,1)]);
elseif Var_P_wave3<1.5 && Var_S_wave2<1.5
Pt=mean([P_matrix(2,1);P_matrix(3,1)]);
St=mean([S_matrix(2,1);S_matrix(3,1)]);
elseif Var_P_wave2<1.5 && Var_S_wave3<1.5
Pt=mean([P_matrix(1,1);P_matrix(2,1)]);
St=mean([S_matrix(1,1);S_matrix(2,1)]);
elseif Var_P_wave3<1.5 && Var_S_wave3<1.5
Pt=mean([P_matrix(2,1);P_matrix(3,1)]);
St=mean([S_matrix(1,1);S_matrix(2,1)]);
else
Pt=min(P_matrix);
St=max(S_matrix);
end
  댓글 수: 2
Torsten
Torsten 2023년 8월 18일
We cannot check your claim because you didn't include executable code.
Jorge Luis Paredes Estacio
Jorge Luis Paredes Estacio 2023년 8월 18일
I think I find the issue, Thank you :)

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

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 8월 18일
편집: Cris LaPierre 2023년 8월 18일
In the example you have shared, var(P_matrix) is not less than 1.5, so the bolded code in the nested if statement is not reached. The condition that is true is Var_P_wave2<1.5 && Var_S_wave2<1.5
P_matrix=[53.9350; 53.95; 54125];
S_matrix=[-1; 60.485; 60.57];
Var_P_wave1=var(P_matrix)
Var_P_wave1 = 9.7456e+08
Var_P_wave2=var([P_matrix(1,1);P_matrix(2,1)])
Var_P_wave2 = 1.1250e-04
Var_P_wave3=var([P_matrix(2,1);P_matrix(3,1)])
Var_P_wave3 = 1.4618e+09
Var_S_wave1=var(S_matrix)
Var_S_wave1 = 1.2619e+03
Var_S_wave2=var([S_matrix(2,1);S_matrix(3,1)])
Var_S_wave2 = 0.0036
Var_S_wave3=var([S_matrix(1,1);S_matrix(2,1)])
Var_S_wave3 = 1.8902e+03
if Var_P_wave1<1.5 && Var_S_wave1<1.5
disp("1")
elseif Var_P_wave1<1.5 && Var_S_wave1>1.5
disp("2")
if Var_S_wave2<1.5 && mean([S_matrix(2,1);S_matrix(3,1)])>=(mean(P_matrix)+0.5*TS_arrival_lag) && mean([S_matrix(2,1);S_matrix(3,1)])<=(mean(P_matrix)+1.5*TS_arrival_lag)
disp("3")
elseif Var_S_wave3<1.5 && mean([S_matrix(1,1);S_matrix(2,1)])>=(mean(P_matrix)+0.5*TS_arrival_lag) && mean([S_matrix(1,1);S_matrix(2,1)])<=(mean(P_matrix)+1.5*TS_arrival_lag)
disp("4")
else
disp("5")
end
elseif Var_P_wave2<1.5 && Var_S_wave2<1.5
disp("6")
elseif Var_P_wave3<1.5 && Var_S_wave2<1.5
disp("7")
elseif Var_P_wave2<1.5 && Var_S_wave3<1.5
disp("8")
elseif Var_P_wave3<1.5 && Var_S_wave3<1.5
disp("9")
else
disp("10")
end
6

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by