Plotting of a rolling ball

조회 수: 3 (최근 30일)
Cem Eren Aslan
Cem Eren Aslan 2024년 5월 24일
편집: VBBV 2024년 5월 24일
Hi all,
I have data as below. First column is time column. The second column is x values and the third column is y values. I want to plot this data.The data shows that a round ball is at the x and y location at given time. This ball seems to be shifting/rolling. How can I plot this movement of the ball? The data is as follows.
Thanks.
0 0 0
0.00500000000000000 -1.99184823748972e-07 1.05798917365090e-13
0.0100000000000000 -9.95522559684969e-07 2.64284044491124e-12
0.0150000000000000 -2.70844960991857e-06 1.95618647719148e-11
0.0200000000000000 -5.57897138597691e-06 8.29997912681309e-11
0.0250000000000000 -9.72602113360498e-06 2.52254632243548e-10
0.0300000000000000 -1.52681885391364e-05 6.21646883377640e-10
0.0350000000000000 -2.24451354098218e-05 1.34342427617396e-09
0.0400000000000000 -3.12528324201816e-05 2.60463875809055e-09
0.0450000000000000 -4.14440486717297e-05 4.58029112081254e-09
0.0500000000000000 -5.27718390114465e-05 7.42631198040007e-09
0.0550000000000000 -6.49895772581970e-05 1.12630537391977e-08
0.0600000000000000 -7.79724695483816e-05 1.62125493532621e-08
0.0650000000000000 -9.15958589238721e-05 2.23728036586717e-08
0.0700000000000000 -0.000105613752470057 2.97447058954838e-08
0.0750000000000000 -0.000119902041788388 3.83373323333985e-08

채택된 답변

VBBV
VBBV 2024년 5월 24일
편집: VBBV 2024년 5월 24일
@Cem Eren Aslan, you can use plot function handle and delete it at end of every iteration inside the loop,
data = [0 0 0
0.00500000000000000 -1.99184823748972e-07 1.05798917365090e-13
0.0100000000000000 -9.95522559684969e-07 2.64284044491124e-12
0.0150000000000000 -2.70844960991857e-06 1.95618647719148e-11
0.0200000000000000 -5.57897138597691e-06 8.29997912681309e-11
0.0250000000000000 -9.72602113360498e-06 2.52254632243548e-10
0.0300000000000000 -1.52681885391364e-05 6.21646883377640e-10
0.0350000000000000 -2.24451354098218e-05 1.34342427617396e-09
0.0400000000000000 -3.12528324201816e-05 2.60463875809055e-09
0.0450000000000000 -4.14440486717297e-05 4.58029112081254e-09
0.0500000000000000 -5.27718390114465e-05 7.42631198040007e-09
0.0550000000000000 -6.49895772581970e-05 1.12630537391977e-08
0.0600000000000000 -7.79724695483816e-05 1.62125493532621e-08
0.0650000000000000 -9.15958589238721e-05 2.23728036586717e-08
0.0700000000000000 -0.000105613752470057 2.97447058954838e-08
0.0750000000000000 -0.000119902041788388 3.83373323333985e-08];
t = data(:,1);
x = data(:,2);
y = data(:,3);
for k = 1:numel(x)
h=plot(x(k), y(k), 'bo', 'MarkerFaceColor', 'b');
pause(2);
delete(h); % deletes the previous location /position of ball in figure
end

추가 답변 (1개)

Animesh
Animesh 2024년 5월 24일
You can use the plot function in MATLAB for simple visualization of the given 2D trajectory.
You can refer the following MATLAB Documention for more information on plot function: www.mathworks.com/help/matlab/ref/plot.html
Moreover, to visualize the movement over time you can use the loop to draw the position of ball at each time step. You can do something like this to visualize the movement:
for i = 1:length(x)
plot(x(i), y(i), 'ro', 'MarkerFaceColor', 'r');
pause(0.1); % Adjust the speed of animation by changing the pause duration
end
  댓글 수: 1
Cem Eren Aslan
Cem Eren Aslan 2024년 5월 24일
First of all, thank you for your answer. The code is worked but all points where the ball passes are visible. How can I make it appear only in the current time period? For example, in the 2nd second, I do not want to see the place where it was seen in the 1st second. How can I do that? I drop a screenshot about result below.

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

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by