이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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.
Walter Roberson
2020년 3월 14일
Error in plottingmesh (line 21)
I need those 20 lines before the problem.
추가 답변 (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 (한국어)