필터 지우기
필터 지우기

If point x belongs to vertices of rectangle?

조회 수: 2 (최근 30일)
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN 2021년 11월 22일
댓글: Jon 2021년 11월 22일
I have defined a rectangle with four points, x1_min, x1_max, x2_min and x2_max. My goal is to create an if cycle with the condition where a point x is any of the four corners of this rectangle.
Instead of writing something like ( (x(1) == x1_min && x(2) == x2_min) || (x(1) == x1_min && x(2) == x2_max) || (x(1) == x1_max && x(2) == x2_min) || (x(1) == x1_max && x(2) == x2_max) ), is there a simpler way?
Thank you in advance!
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];
x = [0.1 0.1];

채택된 답변

Jon
Jon 2021년 11월 22일
편집: Jon 2021년 11월 22일
You could define a 4 by 2 array, corners, with the corner values (first column x values, second column y values) then do something like
if any(all([2,3]==corners,2))
you could also use ismember
ismember([2,3],corners,'rows')
I think using ismember is clearer
  댓글 수: 2
ABCDEFG HIJKLMN
ABCDEFG HIJKLMN 2021년 11월 22일
Thank you!
Jon
Jon 2021년 11월 22일
Your welcome, good luck with your project

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by