フィルターのクリア

Construct if cycle for two variables

1 回表示 (過去 30 日間)
Miguel Albuquerque
Miguel Albuquerque 2022 年 6 月 15 日
編集済み: Walter Roberson 2022 年 6 月 20 日
Hey guys, I just wanted to check with you if this code is right or is there anyway I could improove it?
This is a function: I want that for the two ifs, status=1 and if the two ifs conditions doesnt apply, then ,status=0.
if angle_transmitter + teta_flutuations_transm <= angle_receiver + teta_flutuations_reflec && angle_transmitter - teta_flutuations_transm >= angle_receiver - teta_flutuations_reflec && Vectors_product_2 ~= 1
status=1;
if angle_transmitter + teta_flutuations_transm >= angle_receiver + teta_flutuations_reflec && angle_transmitter - teta_flutuations_transm <= angle_receiver + teta_flutuations_reflec
status=1;
else
status=0;
end

採用された回答

Walter Roberson
Walter Roberson 2022 年 6 月 16 日
status = (angle_transmitter + teta_flutuations_transm <= angle_receiver + teta_flutuations_reflec && angle_transmitter - teta_flutuations_transm >= angle_receiver - teta_flutuations_reflec && Vectors_product_2 ~= 1) ||
(angle_transmitter + teta_flutuations_transm >= angle_receiver + teta_flutuations_reflec && angle_transmitter - teta_flutuations_transm <= angle_receiver + teta_flutuations_reflec)
  2 件のコメント
Miguel Albuquerque
Miguel Albuquerque 2022 年 6 月 20 日
I dont need any if condition?
Walter Roberson
Walter Roberson 2022 年 6 月 20 日
編集済み: Walter Roberson 2022 年 6 月 20 日
This code will return 0 and 1 directly.
If you change all of the && to & and change the | | to | then the code would be vectorized, able to handle arrays of angle_transmitter at the same time

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

その他の回答 (1 件)

Karan Kannoujiya
Karan Kannoujiya 2022 年 6 月 16 日
Hi Miguel,
For checking the above the condition
you will have to use two ifs and this the right way of doing it.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by