Plotting multiple object trajectories together with their identity

조회 수: 3 (최근 30일)
Hari krishnan
Hari krishnan 2019년 5월 3일
댓글: darova 2021년 7월 24일
Hi, I have a matfile 'a' which have the time in the first column, identity of objects from the first row of second column till the end and their X and Y coordinates.
What i want to do is to plot the trajectories of all these objects together like a movie so that i can keep track of the objects along with their identity displayed.
I am able to plot the trajectory for a single choosen object as shown below. Can anyone give an idea ?
Any help to solve this will be appreciated.
%% Loading mat file and keep time and coordinates of individual objects in a cell
load('a.mat')
final_plot_mat_missing_part = a(:,:);
Ucolumnnames_fpm = unique(final_plot_mat_missing_part(1,2:end));
finaL_plot_matrix_cell = cell(1,numel(Ucolumnnames_fpm));
for ii = 1:numel(finaL_plot_matrix_cell) %numel returns the number of elements.
idx_time_needed_f = final_plot_matrix(1,:) == Ucolumnnames_fpm(ii);
finaL_plot_matrix_cell{ii} = [final_plot_mat_missing_part(1:end,3),final_plot_mat_missing_part(1:end,idx_time_needed_f)];
end

채택된 답변

darova
darova 2019년 5월 5일
I always use simple plot() and pause() to animate something
clc, clear, cla
load a.mat
np = 2; %(size(a,2)-1)/2; % number of particles
t = a(2:end,1);
hold on
% trajectories
for i = 2:2:np*2
plot3(t,a(2:end,i),a(2:end,i+1),'COlor',rand(1,3));
end
view(45,45)
xlabel('TIME')
ylabel('X AXIS')
zlabel('Y AXIS')
h = zeros(1,np); % particle handles
for i = 730:50:size(a,1) % frames
k = 0;
t = a(i,1); % time of current frame
for j = 2:2:np*2 % particles
x = a(i,j);
y = a(i,j+1);
k = k + 1;
h(k) = plot3(t,x,y,'or');
end
drawnow
pause(0.1)
delete(h)
end
hold off
Also read about VideoWriter() if you want to create a video
  댓글 수: 8
ADJE JEREMIE ALAGBE
ADJE JEREMIE ALAGBE 2021년 7월 21일
Hi, can someone give an idea on this?
darova
darova 2021년 7월 24일
Please create a separate quesiton

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Clutter에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by