title: Get 3d Coordinate Of Mouse In Axis
body: <p>I used below code from <a href="http://www.mathworks.com/matlabcentral/fileexchange/7594-click3dpoint" rel="nofollow noreferrer">link</a> to plot mouse position in axes(when mouse moving in axes) :</p>
  
  <pre><code>point = get(gca, 'CurrentPoint'); % mouse click position
  camPos = get(gca, 'CameraPosition'); % camera position
  camTgt = get(gca, 'CameraTarget'); % where the camera is pointing to
  camDir = camPos - camTgt; % camera direction
  camUpVect = get(gca, 'CameraUpVector'); % camera 'up' vector
  zAxis = camDir/norm(camDir);
  upAxis = camUpVect/norm(camUpVect);
  xAxis = cross(upAxis, zAxis);
  yAxis = cross(zAxis, xAxis);
  
  rot = [xAxis; yAxis; zAxis]; % view rotation
  rotatedPointFront = rot * point' ;
  plot3(rotatedPointFront(1),rotatedPointFront(2),rotatedPointFront(3), 'r.','MarkerSize', 20)
  </code></pre>
  
  <p>but plotted position differs from mouse location.
  <img src="https://i.stack.imgur.com/rIC7k.png" alt="enter image description here"></p>