How to select one point as the center of the plot
조회 수: 15 (최근 30일)
이전 댓글 표시
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
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
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!