Two conditional operations can be used in matlab or do I need to use double if?

2 ビュー (過去 30 日間)
DulceEien
DulceEien 2021 年 7 月 26 日
コメント済み: DulceEien 2021 年 7 月 27 日
for i = 1:length(beam_spalling.high)
if transversal(i) == 0 && ongitudinal == 0
severity_bs(i) = 2;
elseif transversal(i) == 0 && longitudinal > 0
severity_bs(i) = 3;
elseif transversal(i) > 0 && longitudinal == 0
severity_bs(i) = 3;
else transversal(i) > 0 && longitudinal > 0
severity_bs(i) = 4;
end
end
For the third conditional, could be used another loop to have one or another option?
  2 件のコメント
Yongjian Feng
Yongjian Feng 2021 年 7 月 26 日
For the third one, you meant this:
elseif transversal(i) > 0 && longitudinal == 0
It looks good. What do you want please?
DulceEien
DulceEien 2021 年 7 月 27 日
thank you, I saw my error

サインインしてコメントする。

採用された回答

Rik
Rik 2021 年 7 月 26 日
It looks like you could use a lookup table and skip the entire loop:
transversal=[0 1 0 1];longitudinal=[0 0 1 1];
LUT=[2 3;3 4];
[~,ind1]=find( [transversal(:)==0 transversal(:)>0 ] );
[~,ind2]=find( [longitudinal(:)==0 longitudinal(:)>0] );
severity_bs=LUT(sub2ind(size(LUT),ind1,ind2))
severity_bs = 4×1
2 2 4 4
Note that you have a typo in your second line: it is missing an l.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by