You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Label each data points?
4 views (last 30 days)
Show older comments
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
on 12 Mar 2020
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
Walter Roberson
on 12 Mar 2020
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.
steamrice
on 12 Mar 2020
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)?
Walter Roberson
on 12 Mar 2020
I had no problem putting 1000 labels on
S=string(1:1000).';
text(x, y, z, S)
Walter Roberson
on 12 Mar 2020
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)
Walter Roberson
on 12 Mar 2020
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.
Walter Roberson
on 12 Mar 2020
I would suggest that you consider using datatips to pop up identification for what you are pointing at.
steamrice
on 12 Mar 2020
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...)
Walter Roberson
on 12 Mar 2020
Could you remind us which MATLAB release you are using? datatip capability just changed.
Walter Roberson
on 12 Mar 2020
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"
Walter Roberson
on 12 Mar 2020
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.
steamrice
on 12 Mar 2020
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!
Walter Roberson
on 12 Mar 2020
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.
steamrice
on 13 Mar 2020
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
Walter Roberson
on 14 Mar 2020
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)
Walter Roberson
on 14 Mar 2020
Was there more to the message, like "for input of type graphics.placeholder" ?
Walter Roberson
on 14 Mar 2020
Try
restoredefaultpath
rehash toolboxcache
Walter Roberson
on 14 Mar 2020
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.
steamrice
on 14 Mar 2020
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..?
Walter Roberson
on 14 Mar 2020
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)
steamrice
on 14 Mar 2020
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!?
steamrice
on 14 Mar 2020
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, :);
Walter Roberson
on 14 Mar 2020
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 ?
Walter Roberson
on 14 Mar 2020
Error in plottingmesh (line 21)
I need those 20 lines before the problem.
Walter Roberson
on 14 Mar 2020
I would recommend starting by removing the
clc;clear all; close all
More Answers (1)
steamrice
on 15 Mar 2020
Sorry for the late reply! I tried that and still got the same result..
3 Comments
Walter Roberson
on 15 Mar 2020
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,
steamrice
on 26 Apr 2020
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..
Walter Roberson
on 29 Apr 2020
row = dataTipTextRow('Index: ',i/2);
perhaps?
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)