Clear Filters
Clear Filters

How to select one point as the center of the plot

10 views (last 30 days)
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 Comments
Andrew
Andrew on 1 May 2023
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 on 1 May 2023
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.

Sign in to comment.

Accepted Answer

DGM
DGM on 1 May 2023
Edited: DGM on 1 May 2023
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 Comment
Andrew
Andrew on 1 May 2023
Yes, I love the first option, thank you very much! Exactly what I'm trying to do

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!