필터 지우기
필터 지우기

Plotting users in Matlab

조회 수: 1 (최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2014년 7월 21일
답변: Star Strider 2014년 7월 21일
Hi everyone, I have coded the following figure, in which the users are randomly distributed between the four blocks. I want the users to be only on the street, not inside the building block. Any help will be really appreciated. Thank you guys.

채택된 답변

Star Strider
Star Strider 2014년 7월 21일
Use the inpolygon function:
Compare the two plots:
Users = 2*rand(20,2);
Bldg = [0.5 0.5; 0.5 1.5; 1.5 1.5; 1.5 0.5; 0.5 0.5];
figure(1)
plot(Bldg(:,1), Bldg(:,2))
hold on
scatter(Users(:,1), Users(:,2), 'xb')
hold off
axis([0 2 0 2])
axis equal square
Street = inpolygon(Users(:,1), Users(:,2), Bldg(:,1), Bldg(:,2));
figure(2)
plot(Bldg(:,1), Bldg(:,2))
hold on
scatter(Users(Street==0,1), Users(Street==0,2), 'xb')
hold off
axis([0 2 0 2])
axis equal square

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by