Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Placing the element to the specific area if the condition is satisfied.

조회 수: 1 (최근 30일)
Abdul Mannan
Abdul Mannan 2019년 6월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
I want to write a code for the below problem. A rectangular area is assumed that encompass the area (C) of my problem. The area that are outside of area (C) are represented by exterior, E. The rectangle is the sum of C and E.
The condition is as follows-
In exterior E : e > 0 (e is the deformed distance in my problem)
In actual contact C : e ==0
If e > 0, the element is in the exterior, E
And, if e == 0, the element is in the contact, C
How to write a code in matlab for such a case?

답변 (1개)

Suryaansh Mata
Suryaansh Mata 2019년 6월 18일
Define the area of the rectangle using the two parameters 'x' and 'y'. Now define the range for x and y for the regions E and C. Next make use of AND, OR operators in the if elseif else check blocks to incorporate the logic. A sample example can be.
0 <= x <=10
0<= y < 5 consists of area E
5< y <= 10 consists of area C
This is the region of the rectangle
Now make use of the if conditions as follows
if (y<5)
area is in E
elseif (y==5)
area is in contact
else
area is in C
end
This should be a correct approach to the given problem
  댓글 수: 1
Abdul Mannan
Abdul Mannan 2019년 6월 20일
Thank you Suryaansh Mata for the answer. I have presented my problem again alongwith the code that I have written.
rectangle.jpg
Assume total area of rectangle is Q which is the sum of the area of ellipse (C) and the area of outside of ellipse (E). The rectangle is discretised as follows-
mx, my = total number of discretization element in the x and y directions, respectively.
xl, yl = coordinate of the lower left corner
xh, yh = coordinate of upper right corner
dx, dy = x and y length of each element
I want to write a code that will satisfy the following conditions-
If e > 0, the element is in E.
if e == 0, the element is in C.
Can you please see the below code whether it is correct or not? A major problem I am facing is how to represent the element is in E/C within if statement ? And also, can I express gx and gy with Q as I have writted in the code? Thanks again.
gx = xl:dx:xh; % the elements in the x direction
gy = yl:dy:yh; % the elements in the y direction
Q = [gx; gy]; %%% is it correct to represent gx and gy?
%%% is the Q here represent the rectangle properly?
for i = 1:length(gx)
for j = 1:length(gy)
if (e>0)
E(i,j) = Q(i, j)
end
if (e == 0)
C(i, j) = Q(i, j)
end
end
end

Community Treasure Hunt

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

Start Hunting!

Translated by