comparison number on interval

20 ビュー (過去 30 日間)
Dominik Gajdos
Dominik Gajdos 2024 年 4 月 21 日
コメント済み: Dominik Gajdos 2024 年 4 月 21 日
Hello i have this code, i should get px py pz values when px and py are in interval <-524,524> and pz <0,524>
but it returns values even when i as set them as belowm what doesen't meet conditions
Can anyone help ?
px = 0;
py = 1000;
pz = 0;
if (-524 <= px) && (px <= 524) | (-524 <= py) && (py <= 524) | (0 <= pz) && (pz <= 524)
px
py
pz
else
fig = uifigure;
message = ["Point is out of border of work space","Insert coordinations with max vule 524."];
uialert(fig,message,"Warning","Icon","warning");
end
px = 0
py = 1000
pz = 0
  2 件のコメント
Joshua Levin Kurniawan
Joshua Levin Kurniawan 2024 年 4 月 21 日
Hi Dominik, if you want to print px, py, and pz value in the interval of <-524,524> and <0,524> for px py and pz consecutively, then you must specify:
if ((-524 <= px) && (px <= 524)) && ((-524 <= py) && (py <= 524)) && ((0 <= pz) && (pz <= 524))
Remember that logic AND is denotated && in MATLAB, whereas || means OR. Hence, your code will looks like this:
px = 0;
py = 1000;
pz = 0;
if ((-524 <= px) && (px <= 524)) && ((-524 <= py) && (py <= 524)) && ((0 <= pz) && (pz <= 524)) % <-524,524> for px, py interval and <0,524> for px py AND pz interval
px
py
pz
else
fig = uifigure;
message = ["Point is out of border of work space","Insert coordinations with max vule 524."];
uialert(fig,message,"Warning","Icon","warning");
end
Hope this can help.
Dominik Gajdos
Dominik Gajdos 2024 年 4 月 21 日
yes it works, my thx for help

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

採用された回答

VBBV
VBBV 2024 年 4 月 21 日
px = 0;
py = 1000;
pz = 0;
if (-524 <= px) & (px <= 524) & (-524 <= py) & (py <= 524) & (0 <= pz) & (pz <= 524)
px
py
pz
else
end
  2 件のコメント
VBBV
VBBV 2024 年 4 月 21 日
Use & (and) in place of | (or) in the if-condition
Dominik Gajdos
Dominik Gajdos 2024 年 4 月 21 日
yes this helps thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMarine and Underwater Vehicles についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by