MATLAB Answers

Plotting multiple object trajectories together with their identity

13 ビュー (過去 30 日間)
Hari krishnan
Hari krishnan 2019 年 5 月 3 日
コメント済み: darova 2019 年 10 月 17 日
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

  1 件のコメント

Hari krishnan
Hari krishnan 2019 年 5 月 4 日
Hi, can someone give an idea on this?

サインインしてコメントする。

採用された回答

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

  5 件のコメント

表示 2 件の古いコメント
Hari krishnan
Hari krishnan 2019 年 5 月 5 日
@darova..thank you very much
Chandru Muthusamy
Chandru Muthusamy 2019 年 10 月 17 日
Can you suggest me how to create a.mat file to use in the given programme please.
I tried in this way:
Input:
x = rand(30);
y = magic(30);
z = eye(30);
% Save the variable x,y,z into one *.mat file
save a.mat x y z
% Clear them out of the workspace
clear x y z
Output(Error):
Undefined function or variable 'a'.
Error in Myprg (line 40)
t = a(2:end,1);
darova
darova 2019 年 10 月 17 日
Did you download this file?
123.PNG

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by