How do I plot an animated vertical line?
1 view (last 30 days)
Show older comments
Charles Austin
on 4 Dec 2018
Commented: DERYA DILMEN
on 18 Feb 2021
I want to graph the motion of a diver swimming straight downwards to the sea floor at an x position of 20,000 feet from the origin, touching it the sea floor, then immediatelely ascending directly upward.
In my case, the x-axis represents horizontal distance [0, 20000] and the y-axis is depth [0, -1000]. I want use an overlay plot where both the shark's and diver's motion are animated simultaneously. I have approached it from many directions but have not been able to animate the diver's motion.
What command should I use to illustrate the diver while the shark is swimming towards his boat at the surface?
clc, clear
%Here is the motion of the shark, swimming horizontally towards the diver's boat which is 20k feet away.
x1 = [0:1:20000];
y1 = 0*x1+0;
ax=axes;
title('Shark Motion and Diver Motion')
xlabel('Depth (Feet)')
ylabel('Horizontal Position (Feet)')
grid on
set(ax,'xlim',[0 20000],'ylim',[-1000 0]);
hold (ax);
comet(x1,y1);
%Here is the motion of the diver, swimming from the surface of the water
%straight down 1000 feet to the sea floor, then immediately swimming updard at the
%same speed.
x2 = [0:1:20000]
y2 = 0*x1+0;
set(ax,'xlim',[0 20000],'ylim',[0 -1000]);
comet(x2,y2);
%What command should I use to animate the diver's vertical motion as the
%shark approaches? I cannot get 'comet' to work.
Accepted Answer
Cris LaPierre
on 5 Dec 2018
You cannot have two 'comets' running at the same time using comet. You could look into using this function from the file exchange.
Additional comments:
- Your code is throwing an error about the second 'set' command. The order of your YLim needs to be switched.
- You only need to set the axis limits once, so the second one is actually not necessary
0 Comments
More Answers (0)
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!