Label each data points?
4 次查看(过去 30 天)
显示 更早的评论
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!
采纳的回答
Walter Roberson
2020-3-12
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 个评论
steamrice
2020-3-12
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?
steamrice
2020-3-12
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
Walter Roberson
2020-3-12
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
2020-3-12
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
2020-3-12
I had no problem putting 1000 labels on
S=string(1:1000).';
text(x, y, z, S)
steamrice
2020-3-12
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!
Walter Roberson
2020-3-12
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
2020-3-12
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
2020-3-12
I would suggest that you consider using datatips to pop up identification for what you are pointing at.
steamrice
2020-3-12
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
2020-3-12
Could you remind us which MATLAB release you are using? datatip capability just changed.
Walter Roberson
2020-3-12
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"
steamrice
2020-3-12
I am trying that and put this within my for loop. But its plotting each point in slow motion?
Walter Roberson
2020-3-12
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
2020-3-12
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
2020-3-12
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
2020-3-13
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
2020-3-14
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
2020-3-14
Was there more to the message, like "for input of type graphics.placeholder" ?
steamrice
2020-3-14
Undefined function or variable 'reshape'.
Error in plottingmesh (line 20)
temp = reshape(test.', 3, :);
steamrice
2020-3-14
Thanks for the response! Tried to run twice and closed matlab and reopened it again. The same error popped up again..
Walter Roberson
2020-3-14
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
2020-3-14
I tried it on another computer that has a 2018b matlab version and I got the same error. Undefined function or variable 'reshape'.....
steamrice
2020-3-14
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
2020-3-14
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
2020-3-14
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
2020-3-14
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
2020-3-14
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 ?
steamrice
2020-3-14
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.
更多回答(1 个)
steamrice
2020-3-15
Sorry for the late reply! I tried that and still got the same result..
3 个评论
Walter Roberson
2020-3-15
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
2020-4-26
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..
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)