Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding letters to 3D plot data points in Matlab

Tags:

graph

plot

matlab

I am currently working on a 3D representation of a hand fingers moving. You can see on the picture below how it looks like, since it would be too complicated to describe otherwise:

hand representation

It is an animation, so it's moving constantly. There is one dot for each finger, and one dot for the palm. However, I can't keep track of the fingers. I tried to give them different colors, but it doesn't help a lot.

So the question is:

  • Is there a way to replace the circles, or any other symbol, with an actual letter, or even short word (3-4 letters)?

  • Alternatively (and it is quite a stretch, but why not ask?), would there be a way to draw lines joining these dots together? This is optional, and I might open another question regarding it if necessary.

Thanks!

Here is the actual code; I know it is far from being elegant coding, and am sorry about it, but it works, which is already a great step for me:

clear all
clc

csv=csvread('pilot6/maindroite.csv',1,0); %read the values from a csv
both = csv(:,2:19);

ax=axes;
set(ax,'NextPlot','replacechildren');

Dt=0.1; %sampling period in secs

k=1;
hp1=plot3(both(k,1),both(k,2),both(k,3),'ok'); %get handle to dot object
hold on;
hp2=plot3(both(k,4),both(k,5),both(k,6),'og');
hp3=plot3(both(k,7),both(k,8),both(k,9),'ob');
hp4=plot3(both(k,10),both(k,11),both(k,12),'oc');
hp5=plot3(both(k,13),both(k,14),both(k,15),'om');
hp6=plot3(both(k,16),both(k,17),both(k,18),'or');
hold off;

t1=timer('TimerFcn','k=doPlot(hp1,hp2,hp3,hp4,hp5,hp6,both,t1,k)','Period', Dt,'ExecutionMode','fixedRate');
start(t1);

and the function used:

function k=doPlot(hp1,hp2,hp3,hp4,hp5,hp6,pos,t1,k)

k=k+1;
if k<5000%length(pos)
   set(hp1,'XData',pos(k,1),'YData',pos(k,2),'ZData',pos(k,3));
   axis([0 255 0 255 0 255]);
   set(hp2,'XData',pos(k,4),'YData',pos(k,5),'ZData',pos(k,6));
   set(hp3,'XData',pos(k,7),'YData',pos(k,8),'ZData',pos(k,9));
   set(hp4,'XData',pos(k,10),'YData',pos(k,11),'ZData',pos(k,12));
   set(hp5,'XData',pos(k,13),'YData',pos(k,14),'ZData',pos(k,15));
   set(hp6,'XData',pos(k,16),'YData',pos(k,17),'ZData',pos(k,18));

else
    k=1;
    set(hp,'XData',pos(k,1),'YData',pos(k,2),'ZData',pos(k,3));
   axis([0 255 0 255 0 255]);
end

I just want to mention this is based heavily on Jorge's answer on this question, so thanks to him again

like image 930
Cristol.GdM Avatar asked Jan 09 '12 17:01

Cristol.GdM


People also ask

How do I add text to a graph in MATLAB?

To add text to one point, specify x and y as scalars. To add text to multiple points, specify x and y as vectors with equal length. text( x , y , z , txt ) positions the text in 3-D coordinates. text(___, Name,Value ) specifies Text object properties using one or more name-value pairs.

How do I add a text box to a MATLAB figure?

Create Text Box AnnotationCreate a simple line plot and add a text box annotation to the figure. Specify the text description by setting the String property. Force the box to fit tightly around the text by setting the FitBoxToText property to 'on' .

How do you mark data points in MATLAB?

Create a line plot with 1,000 data points, add asterisks markers, and control the marker positions using the MarkerIndices property. Set the property to the indices of the data points where you want to display markers. Display a marker every tenth data point, starting with the first data point.

How do you plot 3 dimensional data in MATLAB?

plot3( X , Y , Z ) plots coordinates in 3-D space. To plot a set of coordinates connected by line segments, specify X , Y , and Z as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X , Y , or Z as a matrix and the others as vectors.


1 Answers

  1. text(x,y,z,'string') instead of plot3 should work in changing the points to text where [x,y,z] is the coordinate of each point you are plotting.
    Note: calls to set will need to change from set(hp3,'XData',x,'YData',y,'ZData',z) to set(htext,'pos',[x,y,z]). Where hp3 is the handle to a plot3-handle object and htext is a handle to a text-handle object.

  2. To connect the points with a line use plot3(X,Y,Z) where X=[x_1,x_2,...,x_n], Y=[y_1,y_2,...,y_n] and Z=[z_1,z_2,...,z_n].

like image 139
Azim J Avatar answered Sep 24 '22 01:09

Azim J