Plotting trajectory from displacement/time history

I have position data for four points (origin, x, y, and z) which determine a coordinate system. How can I plot the coordinate system trajectory using this data? I would like to have a continuous line for the origin and evenly spaced vectors showing the orientation of the coordinate system.
Thank you in advance.

 채택된 답변

Jonathan Epperl
Jonathan Epperl 2012년 11월 16일

0 개 추천

It would be nice had you included some sample data, so I made up my own, I hope it is somewhat similar
t = linspace(0,pi)';
% Origin
O = [sin(t),cos(t),t.^2];
%
X = O + [ones(1e2,1) rand([1e2 2])*.1];
Y = O + [rand([1e2 1])*.1 ones(1e2,1) rand([1e2 1])*.1];
Z = O + [rand([ 1e2 1])*.1 rand([ 1e2 1])*.1 ones(1e2,1) ];
You'll need a function that plots arrows, I'm not sure whether there is finally a built-in that does that, my guess is no, and so this example is using arrow.m from the FEX http://www.mathworks.com/matlabcentral/fileexchange/278-arrow-m but there are many options, arrow3.m http://www.mathworks.com/matlabcentral/fileexchange/14056-arrow3-version-5 e.g. is a little fancier looking.
stp = 10; % Assuming by 'evenly spaced' you refer to the indices and not
% actual Euclidean distance
plot3(O(:,1),O(:,2),O(:,3)); % Plot the cont. line of origins
axis equal; hold on; % to make it nicer looking
set(gca,'XLim',get(gca,'XLim')+[-1 1]) % Make space for the arrows
set(gca,'YLim',get(gca,'YLim')+[-1 1])
set(gca,'ZLim',get(gca,'ZLim')+[-1 1])
plot3(O(1:stp:end,1),O(1:stp:end,2),O(1:stp:end,3),'o')
arrow([O(1:stp:end,:); O(1:stp:end,:); O(1:stp:end,:)],...
[X(1:stp:end,:); Y(1:stp:end,:); Z(1:stp:end,:)],'Length',15,'Width',2);
hold off
Note that you should do all the axis resizing before plotting the arrows, otherwise the arrows get resized, too, and then it'll look pretty ugly.

댓글 수: 1

Thank you, Jonathan; and from now on I will include sample data with my questions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by