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!

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Mzo. de 2020

1 voto

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 comentarios

steamrice
steamrice el 12 de Mzo. de 2020
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
steamrice el 12 de Mzo. de 2020
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
Walter Roberson el 12 de Mzo. de 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
steamrice el 12 de Mzo. de 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
Walter Roberson el 12 de Mzo. de 2020
I had no problem putting 1000 labels on
S=string(1:1000).';
text(x, y, z, S)
steamrice
steamrice el 12 de Mzo. de 2020
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
Walter Roberson el 12 de Mzo. de 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)
steamrice
steamrice el 12 de Mzo. de 2020
Thanks! The plot seems does not really give us much info tho..
Walter Roberson
Walter Roberson el 12 de Mzo. de 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
Walter Roberson el 12 de Mzo. de 2020
I would suggest that you consider using datatips to pop up identification for what you are pointing at.
steamrice
steamrice el 12 de Mzo. de 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
Walter Roberson el 12 de Mzo. de 2020
Could you remind us which MATLAB release you are using? datatip capability just changed.
steamrice
steamrice el 12 de Mzo. de 2020
Thanks for the response! its R2019a
Walter Roberson
Walter Roberson el 12 de Mzo. de 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"
steamrice
steamrice el 12 de Mzo. de 2020
I am trying that and put this within my for loop. But its plotting each point in slow motion?
steamrice
steamrice el 12 de Mzo. de 2020
Still waiting it to be finished.
Walter Roberson
Walter Roberson el 12 de Mzo. de 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
steamrice el 12 de Mzo. de 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
Walter Roberson el 12 de Mzo. de 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
steamrice el 13 de Mzo. de 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
steamrice
steamrice el 14 de Mzo. de 2020
?Sorry for asking this simple question. Or is it becuase the version i use?
Walter Roberson
Walter Roberson el 14 de Mzo. de 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
Walter Roberson el 14 de Mzo. de 2020
Was there more to the message, like "for input of type graphics.placeholder" ?
steamrice
steamrice el 14 de Mzo. de 2020
Undefined function or variable 'reshape'.
Error in plottingmesh (line 20)
temp = reshape(test.', 3, :);
Walter Roberson
Walter Roberson el 14 de Mzo. de 2020
Try
restoredefaultpath
rehash toolboxcache
steamrice
steamrice el 14 de Mzo. de 2020
Thanks for the response! Tried to run twice and closed matlab and reopened it again. The same error popped up again..
Walter Roberson
Walter Roberson el 14 de Mzo. de 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
steamrice el 14 de Mzo. de 2020
I tried it on another computer that has a 2018b matlab version and I got the same error. Undefined function or variable 'reshape'.....
steamrice
steamrice el 14 de Mzo. de 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
Walter Roberson el 14 de Mzo. de 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
steamrice el 14 de Mzo. de 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
steamrice el 14 de Mzo. de 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
Walter Roberson el 14 de Mzo. de 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 ?
steamrice
steamrice el 14 de Mzo. de 2020
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
Walter Roberson el 14 de Mzo. de 2020
Error in plottingmesh (line 21)
I need those 20 lines before the problem.
steamrice
steamrice el 14 de Mzo. de 2020
I commented the for loop I had
Walter Roberson
Walter Roberson el 14 de Mzo. de 2020
I would recommend starting by removing the
clc;clear all; close all

Iniciar sesión para comentar.

Más respuestas (1)

steamrice
steamrice el 15 de Mzo. de 2020

0 votos

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

3 comentarios

Walter Roberson
Walter Roberson el 15 de Mzo. de 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
steamrice el 26 de Abr. de 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
Walter Roberson el 29 de Abr. de 2020
row = dataTipTextRow('Index: ',i/2);
perhaps?

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 12 de Mzo. de 2020

Comentada:

el 29 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by