필터 지우기
필터 지우기

How to select one point as the center of the plot

조회 수: 15 (최근 30일)
Andrew
Andrew 2023년 4월 30일
댓글: Andrew 2023년 5월 1일
Hi I have a 3d scatter plot where I can select specific datasets in my table
ix=iswithin(T.Num,12,25)
hSc3 = scatter3(T.CED(ix),T.r(ix),T.E0(ix),'filled');
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
end
My question is, what would I need to do to select a specific element to be the center of the plot (i.e. a specific "ix" as the origin) and everything else i splotted around it.
Please let me know, thanks!
  댓글 수: 5
Andrew
Andrew 2023년 5월 1일
right now the points that are selected for the plot is defined from:
ix=iswithin(T.Num,12,25) (i.e. rows 12-25)
I'm trying to figure out what i need to do if I want ix=18 to be the center for example.
Star Strider
Star Strider 2023년 5월 1일
If I understand your question correctly, I would get the values of that point’s (x,y,z) coordinates, and subtract those values from every point in the plot. That point becomes the centre, and all the others shift appropriately.

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

채택된 답변

DGM
DGM 2023년 5월 1일
편집: DGM 2023년 5월 1일
I see two answers, depending on the interpretation of the question.
Perhaps you want to center a reference point in the axes.
% generate some fake data
rng(123)
n = 20;
x = rand(n,1);
y = rand(n,1);
z = rand(n,1);
% specify reference point
refidx = 6;
ref = [x(refidx) y(refidx) z(refidx)];
% create the scatter plot
scatter3(x,y,z,30,z,'filled');
% mark the reference point for clarity
hold on
plot3(ref(1),ref(2),ref(3),'+','markersize',10)
% adjust limits so that marker is centered in the axes
xlim(ref(1) + [-1 1]*max(abs(xlim - ref(1))));
ylim(ref(2) + [-1 1]*max(abs(ylim - ref(2))));
zlim(ref(3) + [-1 1]*max(abs(zlim - ref(3))));
Or perhaps you want to shift all the points such that the reference point is at [0 0 0]
% generate some fake data
rng(123)
n = 20;
x = rand(n,1);
y = rand(n,1);
z = rand(n,1);
% specify reference point
refidx = 6;
ref = [x(refidx) y(refidx) z(refidx)];
% offset the data
xos = x-ref(1);
yos = y-ref(2);
zos = z-ref(3);
% create the scatter plot
scatter3(xos,yos,zos,30,z,'filled');
% mark the reference point for clarity
hold on
plot3(0,0,0,'+','markersize',10)
  댓글 수: 1
Andrew
Andrew 2023년 5월 1일
Yes, I love the first option, thank you very much! Exactly what I'm trying to do

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by