フィルターのクリア

"If number belongs in the interval defined by a matrix" into code?

3 ビュー (過去 30 日間)
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN 2021 年 10 月 27 日
コメント済み: ABCDEFG HIJKLMN 2021 年 10 月 27 日
Hello, I am trying to veto if two given numbers belong in two admissible ranges. Instead of writing line 11 that way, could I instead say something like if x_ini' does not belong to x_bound? Meaning that if the value of the first row of the transposed vector x_ini (i.e. x1_0) does not belong in the interval defined by the first row of matrix x_bound (i. e. x1_min x1_max) and/or, likewise, if the value of the second row of the transposed vector x_ini (i.e. x2_0) is not in the interval defined by the second row of matrix x_bound ((i. e. x2_min x2_max)), then that message is displayed?
Hopefully I have been clear? Thank you in advance for the help!
x1_min = 0.1;
x1_max = 2.0;
x2_min = 0.1;
x2_max = 2.5;
x_bound = [x1_min x1_max ; x2_min x2_max];
x1_0 = 1;
x2_0 = 1;
x_ini = [x1_0 x2_0];
if x1_0 < x1_min || x2_0 < x2_min || x1_0 > x1_max || x2_0 > x2_max
disp("Initial value of x does not belong in admissible interval.");
quit
end
  2 件のコメント
Johan
Johan 2021 年 10 月 27 日
Hello, you can use:
if any([x_ini < x_bound(:,1)',x_ini > x_bound(:,2)'])
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN 2021 年 10 月 27 日
thank you!

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by