Correcting the label in a 3D scatter plot

Hello there,
I have a .xls file that contains x,y,z vertics. The sequence goes something like this (that header of each): x0,y0,z0,x1,y2,z2,..........x1000,y1000,z1000. (3000points in total) Each x,y,z together forms a point I see in the scatter 3D point. I am wondering how to identity/access that particular point properly, say x0,y0,z0 will be verticx 0, x1000,y1000,z1000 will be verticx 1000.
That's what I have from the help eailer:
clc;clear all;
[num,txt,raw] = xlsread('test_april24.csv');
for i = 1:3:3000
a = num(3,i);
b = num(3,i+1);
c = num(3,i+2);
k=scatter3(a,b,c, 'filled');
S=string(1:3000).';
text(a, b, c, S);
row = dataTipTextRow('Index: ',i');
k.DataTipTemplate.DataTipRows(end+1) = row;
hold on
end
The index number is now just showing one of the axis (since its based on the total number i) say index 3000 but I am expecting 1000
In addition, when the index popped up, is there a way that I can access a participant point that I am interested? say x100,y100,z100 (verticx100)?
Many thanks!

5 Commenti

You forgot to attach 'test_april24.csv'. Make it easy for us to help you.
Can't run the script
I attached that and hope that I illsutated what i was trying to achieve! Thanks for your time
Sorry I uploaded the .csv one now
Are you able to open that? @darova
Thanks

Accedi per commentare.

 Risposta accettata

darova
darova il 27 Apr 2020
I used currentPoint property of callback to get coordinates of mouseclick
currentPoint returns 2 points in 3D space. I used crossp roduct to find closest point
See script inside

8 Commenti

steamrice
steamrice il 27 Apr 2020
Modificato: steamrice il 27 Apr 2020
Thanks for the response! I am wondering should I keep what I had or just call your function directly after my for loop? Beacause I would need to read my excel file first
Use this function after for loop.
Thanks for the response! I saw those 10 random points plotted together on my data and it pops with the corresponding vertex (vertex 1 to vertex 10). However, I am trying to acheive the proper indexing on the original data (corresponding to the excel file header)?
I copied 3d row of excel file into text file
Put this part inside the script
a = load('data.txt');
n = fix(length(a)/3)*3;
x = a(1:3:n);
y = a(2:3:n);
z = a(3:3:n);
h = plot3(x,y,z,'.r');
axis vis3d
Wow! Thats what I am trying to achieve! I am trying to replace the x,y,z =rand(10,1) with you mentioned above and it worked!
So did you just tried to copy the .csv file into a text file directly? (without the header)
I couldn't import data from excel file. So i just saved some as txt
No problem! Thanks for the suggestions here.
That's what I was trying to achieve there. If you don't mind ask a follow up question, is the vertex that I see here corresponding to the header of the excel? I am wondering is there a way for me to verifiy this? Like if click vertex 1, would it be able to show its x,y,z component so I can go back to the excel/ text file to verfiy that?
Sure. Go inside callback function and add this line
% line(x(ix),y(ix),z(ix),'marker','*')
[x(ix) y(ix) z(ix)]

Accedi per commentare.

Più risposte (1)

If you want vertex 100, just use that index to get the x, y, and z values:
x100 = x(100);
y100 = y(100);
z100 = z(100);

7 Commenti

Thanks for the response! I am trying that! But also the other question I had was is it possbile to show x0,y0,z0 as index 0 rather than a column number? The current situaition is that the index is only referring to one of the axises, which I will have to go back to the excel to check the column number...
Not sure what that means. There is no row zero or index zero in a matrix. In MATLAB all matrices start with row 1 and column 1. So I assume x0,y0,z0 are all in index 1, so what's wrong with saying
x0 = x(1);
y0 = y(1);
z0 = z(1);
Sorry for not being clear. I mean I would like to match the index I see in the plot to the excel header. Say x0,y0,z0, I would hope it corresponds to index 0 rather than a column number, say 5...
Still not sure what you mean. MATLAB uses 1-based arays, not 0-based arrays like C++. See the FAQ: FAQ #22 Subscript_indices_must_either_be_real_positive_integers_or_logicals
Thanks for response! I think maybe attaching an image might help here
I was testing with these two lines, txt is 1x3000 index and I tried to convert it to 3000x1 string. They are the header you'd see in the excel file ("v0_x", "v0_y", "v0_z" ..."v3000_x", "v3000_y", "v3000_z" 0
index=string(txt.');
row = dataTipTextRow('Index: ',index);
The problem I am having and wanting to achieve, as you can see in the picture, is the index is not showing it properly. The two points that I click, they both showed v0x (in fact, as of now, all points is v0x becase of the above code). I want to have the index properly corresponds to its x,y,z component (matching the excel file).
Does that mean more sense.. Thanks!
No, but it looks like darova figured out what you want and solved it because you accepted his/her answer.

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by