divide the rectangle into the strip in matlab

조회 수: 2 (최근 30일)
ha ha
ha ha 2018년 4월 26일
답변: Viswadeep Lebakula 2021년 7월 20일

Let' say I have the matrix P contain 2D point data(20 points):

1	2	
1.5	2	
2	2	
2.5	2	
3	2	
3.5	2	
4	2	
4.5	2	
5	2	
5.5	2	
1	4	
1.5	4	
2.5	4	
3.5	4	
4	4	
4.5	4	
5	4	
5.5	4	
4.5	3	
1.5	3

And, from that data, I can draw the boundary of data. The result is rectangular shape as bellow image:

And then, I want to divide the rectangle into the strip with user-defined width as follow:

답변 (1개)

Viswadeep Lebakula
Viswadeep Lebakula 2021년 7월 20일
Filename ='P.csv';
data = csvread(Filename);
xmin = min(data(:, 1));
xmax = max(data(:, 1));
ymin = min(data(:, 2));
ymax = max(data(:, 2));
figure;
scatter(data(:, 1),data(:, 2),15,"filled");
xlabel('X - Axis')
ylabel('Y - Axis')
hold on;
rectangle('Position',[xmin ymin xmax-xmin ymax-ymin],'EdgeColor','r',...
'LineWidth',1.2)
% Calculating length and strips
Polygon_Length = max(xmax-xmin,ymax-ymin);
Userdefined_Strip_Width = 1;
strips = Polygon_Length/Userdefined_Strip_Width;
% Dividing rectangle into multiple strips
for i = 1:strips
x1= xmin + (i*Userdefined_Strip_Width);
y1= ymax;
x2= xmin + (i*Userdefined_Strip_Width);
y2= ymin;
plot([x1 x2], [y1 y2])
end

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by