if and else loop problem

조회 수: 4 (최근 30일)
CHANDRABHAN Singh
CHANDRABHAN Singh 2021년 12월 26일
댓글: CHANDRABHAN Singh 2022년 1월 5일
if (loop==false && centre(ii,1)<95 )
centre(ii,:) = centre(ii,:)+ [0.1 0];
elseif (loop==false && centre(ii,2)<95)
centre(ii,:) = centre(ii,:)+ [0 0.1];
elseif (loop==false && centre(ii,1)>5)
centre(ii,:) = centre(ii,:)- [0.1 0];
elseif (loop==false && centre(ii,2)>5)
centre(ii,:) = centre(ii,:)- [0 0.1];
else
break
end
Lets's say centre(ii,1)=94.95, then the first if increases it to 95.05.
As soon as centre(ii,1)=95.05, the third condition makes it again 94.95 and the process continues. I want, once the first condition is achieved i.e. x>95, it should go to third condition. The similar case is for 2nd and 4th condition. How to do this?
  댓글 수: 19
Walter Roberson
Walter Roberson 2022년 1월 4일
Maybe use polyshape() objects and intersect() ?
CHANDRABHAN Singh
CHANDRABHAN Singh 2022년 1월 5일
@Walter Roberson, thank you for your kind support.
Let's say
these are two non interscting ploygons (shown below). How can i get a logical relationship out of this. Something like, if the polygons intersect or touch
paramter = true;
otherwise
parameter = false;
x1 =[-2.6967 -2.0891 -0.0846 1.5544 2.6872 -2.6967];
x2 = [5.6494 6.6386 6.6898 4.0313 1.3002 1.9802 5.6494];
y1 = [ 0.1340 -1.7104 -2.6987 -2.2076 -0.2624 0.1340];
y2 = [1.8624 3.4274 4.2346 6.6998 3.9686 2.2082 1.8624];
plot(x1,y1,x2,y2);
grid on;
poly1 = polyshape(x1',y1');
poly2 = polyshape(x2',y2');
polyout = intersect(poly1,poly2);

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

답변 (1개)

Shanmukha Voggu
Shanmukha Voggu 2021년 12월 29일
Hi,
Adding to comments above, This link here might be helpful.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by