How to remove lines' segments located outside square?
이전 댓글 표시
Hi all, The following code is used to draw multiple lines and square of area (1x1);
%%PLOT lines
deg = 0 : 5 : 90;
r=2;
x_ax = r*[zeros(size(deg(:))) cosd(deg(:))];
y_ax = r*[zeros(size(deg(:))) sind(deg(:))];
plot(x_ax', y_ax', 'LineWidth',1)
hold on
%%Plot square
x1=0;
x2=1;
y1=0;
y2=1;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
The output would be as the following image;

My question is;
How to remove the multiple lines' segments that are located outside the (1x1) square?
So, the output should be like that;

Any suggestions for code to do that?
댓글 수: 1
Image Analyst
2020년 2월 1일
Original question by Erman, in case he also deletes this one:
How to remove the multiple lines' segments that are located outside the (1x1) square?
Hi all, The following code is used to draw multiple lines and square of area (1x1);
%%PLOT lines
deg = 0 : 5 : 90;
r=2;
x_ax = r*[zeros(size(deg(:))) cosd(deg(:))];
y_ax = r*[zeros(size(deg(:))) sind(deg(:))];
plot(x_ax', y_ax', 'LineWidth',1)
hold on
%%Plot square
x1=0;
x2=1;
y1=0;
y2=1;
x = [x1, x2, x2, x1, x1];
y = [y1, y1, y2, y2, y1];
plot(x, y, 'b-', 'LineWidth', 2.5);
grid on
grid minor
axis equal
xlim([-0.2,1.2])
ylim([-0.2,1.2])
The output would be as the following image;

My question is;
How to remove the multiple lines' segments that are located outside the (1x1) square?
So, the output should be like that;

Any suggestions for code to do that?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
