Plotting multiple object trajectories together with their identity
4 ビュー (過去 30 日間)
古いコメントを表示
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
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Vehicle Scenarios についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!