Issue with multiple If condition
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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_wave2=var([P_matrix(1,1);P_matrix(2,1)])
Var_P_wave3=var([P_matrix(2,1);P_matrix(3,1)])
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)])
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
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!