Make array of coordinates from matrix and make the animation of moving coordinate one by one

2 次查看(过去 30 天)
I have the code like this
function dx = trainfinalmodel(t,x)
%Parameter Massa
m1 = 8095; % massa train set 1 dalam kg
m2 = 8500; % massa train set 2 dalam kg
g = 10;
%Parameter Gaya
f1 = 205.10^3; % dalam N
f2 = 302.10^3; % dalam N
c_0_1 = 0.01176;
c_1_1 = 0.00077616;
c_2_1 = 4.48 ;
c_0_2 = 0.01176 ;
c_1_2 = 0.00077616;
c_2_2 = 4.48;
v_0 = 300;
hstar = 120;
a_1 = -1./m1.*(c_1_1 + 2.*c_2_1.*v_0);
a_2 = -1./m2.*(c_1_2 + 2.*c_2_2.*v_0);
a_1_head = 1-(a_1.*hstar);
a_2_head = 1-(a_2.*hstar);
b = 1;
p_1 = -1./m1.*(c_0_1 - c_2_1.*(v_0).^2);
p_2 = -1./m2.*(c_0_2 - c_2_2.*(v_0).^2);
x = [x(1);x(2);x(3);x(4)];
A = [0 a_1_head 0 0;
0 0 0 0;
0 (a_2_head - 1) 0 a_2_head;
0 0 0 0
];
B = [-b.*hstar 0;
b 0;
0 -b.*hstar;
-b b
];
U_t = [f1; f2;];
W = [((a_1 - 1).*v_0) - (p_1.*hstar);
0;
((a_2 - 1).*v_0) - (p_2.*hstar);
((a_1 - 1).*v_0) - (p_1.*hstar);
];
dx = (A*x) + (B*U_t) + W;
end
and for the simulation
clear all, close all
tspan = [0:0.01:1000];
x0 = [0; 0; 100; 0];
[t,x] = ode45(@trainfinalmodel,tspan,x0);
plot(t,x)
legend('x1','x2','x3','x4')
title('Non Linear Model')
xlabel('Waktu(s)')
ylabel('Jarak(m)')
figure(2)
subplot(2,1,1);
hax1 = plot(t,x(:,1),t,x(:,3))
title('Posisi Rangkaian Kereta')
xlabel('Waktu(s)')
ylabel('Jarak(m)')
legend('x_1','x_3')
subplot(2,1,2);
hax2 = plot(t,x(:,2),t,x(:,4))
title('Kecepatan Rangkaian Kereta')
xlabel('Waktu(s)')
ylabel('Kecepatan(m/s)')
legend('x_2','x_4')
I get the graphics after that i want to know the array of coordinates from the graphics. After i get the array of coordinates, i want to make animation for the x y coordinates. So i can plot one by one coordinates. I plot the first and second coordinates, after that i erase the first coordinates and do it next untll all coordinates so i can get the animation when the coordinates is plot form the first untill the end. How i can simulate that?

采纳的回答

Kevin Joshi
Kevin Joshi 2020-6-2
Please check the attached code.
  3 个评论
Ivan Dwi Putra
Ivan Dwi Putra 2020-6-3
编辑:Ivan Dwi Putra 2020-6-3
or get the array of coordinate from matrix. From the code, get the x matrix 100001x4 double. How i can get all coordinates from x1 until x4
my matrix x = [x1;x2;x3;x4]
in my plot only plot x so i confuse how i get coordinate x and y all my matrix
the coordinates is used to simulate the train is moving from one location to another location

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by