Effacer les filtres
Effacer les filtres

How to select one point as the center of the plot

15 vues (au cours des 30 derniers jours)
Andrew
Andrew le 30 Avr 2023
Commenté : Andrew le 1 Mai 2023
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 commentaires
Andrew
Andrew le 1 Mai 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 le 1 Mai 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.

Connectez-vous pour commenter.

Réponse acceptée

DGM
DGM le 1 Mai 2023
Modifié(e) : DGM le 1 Mai 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 commentaire
Andrew
Andrew le 1 Mai 2023
Yes, I love the first option, thank you very much! Exactly what I'm trying to do

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Tags

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by