select and extract only some coordinates of a 3D object

조회 수: 4 (최근 30일)
Alberto Acri
Alberto Acri 2022년 12월 23일
댓글: Fabio Freschi 2022년 12월 23일
I have the following .txt file (Rx3 matrix).
rabbit = importdata("rabbit.txt");
figure
plot3(rabbit(:,1), rabbit(:,2), rabbit(:,3),'k.','Markersize',5)
grid off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
I want to be able to extract only the coordinates of some nodes such as this area:
xlim([-10 -4])
ylim([-6 0])
zlim([11 16])
Could also be useful something like this that I found at the following link.
  댓글 수: 2
Fabio Freschi
Fabio Freschi 2022년 12월 23일
Do you want to use the mouse and click on each point? Or rather you want to extract the subset of nodes in the region you specified?
Alberto Acri
Alberto Acri 2022년 12월 23일
I want to extract the subset of nodes in the region you specified

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

채택된 답변

Fabio Freschi
Fabio Freschi 2022년 12월 23일
Is this what you are asking?
% your code
rabbit = importdata("rabbit.txt");
figure
plot3(rabbit(:,1), rabbit(:,2), rabbit(:,3),'k.','Markersize',5)
grid off
axis equal
xlabel('x')
ylabel('y')
zlabel('z')
% range
xRange = [-10 -4];
yRange = [-6 0];
zRange = [11 16];
% indices of points in the range
idx = rabbit(:,1) >= xRange(1) & rabbit(:,1) <= xRange(2) & ...
rabbit(:,2) >= yRange(1) & rabbit(:,2) <= yRange(2) & ...
rabbit(:,3) >= zRange(1) & rabbit(:,3) <= zRange(2);
% plot in red
hold on
plot3(rabbit(idx,1), rabbit(idx,2), rabbit(idx,3),'ro','Markersize',5)
  댓글 수: 2
Alberto Acri
Alberto Acri 2022년 12월 23일
Yes exactly. However, can you tell me how to save the coordinates you selected in red in an array?
Fabio Freschi
Fabio Freschi 2022년 12월 23일
Sure! Simply get the coordinates that were plotted
rabbithead = [rabbit(idx,1), rabbit(idx,2), rabbit(idx,3)];

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by