Label each data points?

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 (1000data points for each x,y,z). I am wondering is it possible to use scratter3 to plot the points with its label (x0,y0,z0,x1,y2,z2,..........x1000,y1000,z1000) so I can identity/access that particular point?
Many thanks!

 Accepted Answer

Walter Roberson
Walter Roberson on 12 Mar 2020

1 vote

scatter3 cannot do labels.
You can text() and pass it vectors of x y z and a cell array of character vectors that are corresponding labels or a string array. For example string(1:1000).'

37 Comments

I see! So I will save each data point as a text such that I have the varaible access in the workplace? Will it be overloaded?
Warning: Error creating or updating Text
Error in value of property String
Text length might be too long to display.
Just tested that and had this warning and the text is not being plotted
No just do one text() call. You would only need to record the handle if you want to move the points without recreating the text object.
I would have to test the warning that you are getting.
I think its saved all the header as text! However, I think plotting it is not possbile due to its length. What would be a better way to asscess/orginaize the point based on its sequence (rather than saving the 1000 points in the workplace)?
I had no problem putting 1000 labels on
S=string(1:1000).';
text(x, y, z, S)
Sorry! I have 1000 data point for each x,y,z so its 3000 point! Sorry from that last post I missed half of my data!
N=1000 ;
x=rand(N, 1);
y=rand(N, 1);
z=rand(N, 1);
scatter3(x, y, z)
S=string(1:N).';
text(x, y, z, S)
Thanks! The plot seems does not really give us much info tho..
It's a random plot, it is not likely to make sense. The point was to prove that the technology worked, allowing you to go back to your code to compare to see where you were going wrong.
I would suggest that you consider using datatips to pop up identification for what you are pointing at.
Thanks for the response! I did as you suggested. I used datatip(k,x,y,z); where k=scartter3(x,y,z). There are still the same warning and not poping up its hearder. When I clicked one of the data points on the plot and it only showed me the x,y,z data point values (no header included...)
Could you remind us which MATLAB release you are using? datatip capability just changed.
Thanks for the response! its R2019a
row = dataTipTextRow('Index: ', string(1:N).');
k.DataTipTemplate.DataTipRows(end+1) = row;
datacursormode on
Now clicking on a point should pop up a datatip that includes X, Y, Z, and "Index"
I am trying that and put this within my for loop. But its plotting each point in slow motion?
Still waiting it to be finished.
N=1000 ;
x=rand(N, 1);
y=rand(N, 1);
z=rand(N, 1);
k = scatter3(x, y, z);
S = string(1:N).';
dtrow = dataTipTextRow('Index: ', S);
k.DataTipTemplate.DataTipRows(end+1) = dtrow;
datacursormode on
Plotting time: approximately 1/2 second.
I used your previous suggestion using the for loop due to the seperation by 3 columns.
for i = 1:3:3000-2
a = test(:,i);
b = test(:,i+1);
c = test(:,i+2);
scatter3(a,b,c, '*');
hold on
k = scatter3(x, y, z);
S = string(1:3000).';
dtrow = dataTipTextRow('Index: ', S);
k.DataTipTemplate.DataTipRows(end+1) = dtrow;
datacursormode on
hold on
end
This does take me a while to plot all the points. And all the index is showing only Index 1? Would it be possible to get the corresponding header?
Many thanks for the effort!
You should have stuck with my short form code:
temp = reshape(test.', 3, :);
k = scatter3(temp(1,:), temp(2,:), temp(3,:), '*');
After which
S = string(1:size(test,1)).';
dtrow = dataTipTextRow('Index: ', S);
k.DataTipTemplate.DataTipRows(end+1) = dtrow;
datacursormode on
No loop.
Thanks for the response! Is there a toolbox required for using reshape? I tried that and it popped up with an error
Undefined function or variable 'reshape'.
I tried to google it and it does not have mention toolbox for reshape? Hmmm
?Sorry for asking this simple question. Or is it becuase the version i use?
https://www.mathworks.com/help/matlab/ref/reshape.html
Basic matlab, been present as long as I know. It existed by MATLAB 3, probably earlier (I have not seen the documentation for MATLAB 1)
Was there more to the message, like "for input of type graphics.placeholder" ?
Undefined function or variable 'reshape'.
Error in plottingmesh (line 20)
temp = reshape(test.', 3, :);
Try
restoredefaultpath
rehash toolboxcache
Thanks for the response! Tried to run twice and closed matlab and reopened it again. The same error popped up again..
The restoredefaultpath is not a permanent solution. If it works for you for your current session then
savepath
to make the change permanent.
If restoredefaultpath does not work then you will probably need to reinstall MATLAB. reshape is a very fundamental part of MATLAB and not being able to find it would cause a lot of difficulty.
I tried it on another computer that has a 2018b matlab version and I got the same error. Undefined function or variable 'reshape'.....
But when I typed
help reshape
reshape Reshape array.
reshape(X,M,N) or reshape(X,[M,N]) returns the M-by-N matrix
whose elements are taken columnwise from X. An error results
if X does not have M*N elements.
reshape(X,M,N,P,...) or reshape(X,[M,N,P,...]) returns an
N-D array with the same elements as X but reshaped to have
the size M-by-N-by-P-by-.... The product of the specified
dimensions, M*N*P*..., must be the same as NUMEL(X).
reshape(X,...,[],...) calculates the length of the dimension
represented by [], such that the product of the dimensions
equals NUMEL(X). The value of NUMEL(X) must be evenly divisible
by the product of the specified dimensions. You can use only one
occurrence of [].
See also squeeze, shiftdim, colon.
The following comes up...
Or is that a way of not using reshape but still acheive my goal..?
Avoiding reshape:
x = temp(:,1:3:end);
y = temp(:,2:3:end);
z = temp(:,3:3:end);
k = scatter3(x(:), y(:), z(:), '*');
Question: what happens if you try this at the command line:
clear all
reshape(1:4, 2, 2)
The first above would be the other suggestions you suggested eariler? But this one would not be able to get the header for each point?
I trield that and I got
clear all
reshape(1:4, 2, 2)
ans =
1 3
2 4
It means reshape should be working!?
Would it becuase the way I loaded the .csv? I have
[num,txt,raw] = xlsread('datatesting.csv');
temp = reshape(num.', 3, :);
The error comes:
Undefined function or variable 'reshape'.
Error in plottingmesh (line 21)
temp = reshape(num.', 3, :);
I do not understand at the moment how the reshape(1:4, 2, 2) could be working but then you get that error about reshape.
Is it possible that you accidentally assigned to a variable named path ? What are the lines of code leading up to the reshape ?
I have clc;clear all; close all at the very beiginning.
[num,txt,raw] = xlsread('datatesting.csv');
temp = reshape(num.', 3, :);
The line before reshape is just reading the file.
Error in plottingmesh (line 21)
I need those 20 lines before the problem.
I commented the for loop I had
I would recommend starting by removing the
clc;clear all; close all

Sign in to comment.

More Answers (1)

steamrice
steamrice on 15 Mar 2020

0 votes

Sorry for the late reply! I tried that and still got the same result..

3 Comments

Sorry, there is not much more I can do without all the code to the point of error (including comments), but you seem very reluctant to provide it,
Sorry for left you hanged. I was working on the other project. The below code from you suggested eailer work!
clc;clear all;
[num,txt,raw] = xlsread('test_april24.csv'); %change the excel file name when received the new one
for i = 2:3:3002-2
a = num(3,i);
b = num(3,i+1);
c = num(3,i+2);
k=scatter3(a,b,c, 'filled');
S=string(1:3662).';
text(a, b, c, S);
row = dataTipTextRow('Index: ',i');
k.DataTipTemplate.DataTipRows(end+1) = row;
hold on
end
The label also showing the the point. However, if I can ask one more question, from what I understand, the 3D plot I am seeing and each point is coming from each x,y,z (x1,y1,z1 forms a point). And the label is showing the total point 3002. Is there a way to group the index point? (x1,y1,z1 would label as index 1and x3000,y3000,z3000 would label as 1500)?
I have been trying to modifiy this line,
row = dataTipTextRow('Index: ',i');
to somthing like
index=1:1500
row = dataTipTextRow('Index: ',index');
But it would only shows index as all 1 (i think it did not work if I do that inside the for loop..)
Sorry my thought process is a bit messy..
row = dataTipTextRow('Index: ',i/2);
perhaps?

Sign in to comment.

Products

Tags

Community Treasure Hunt

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

Start Hunting!