How to combine animations, add title and edit limits
1 view (last 30 days)
Grigorios Chatziandreou on 14 Apr 2022
Hello, how could i animate these 3 motions together as a smooth one? They seem to show up as different figures, once the one finishes animating the next one starts.
% L = 1;
x = L*sin(thet);
y = -L*cos(thet);
set(gca,'XTick',, 'YTick',, ...
plh_bar = plot([0,x(1)],[0,y(1)],'-k','LineWidth',2); % Pendulum arm
plh_bob = plot(x(1),y(1),'.k','MarkerSize',30); % Pendulum bob
plot(0,-0.045,'^r','MarkerSize',10,'MarkerEdgeColor','red','MarkerFaceColor',[1 .6 .6]) % Pivot
while toc < t(end)
[~,idx] = min(abs(t - toc));
Also I want to add the following but dont know where:
title('ROOF MOTION REPRESENTATION','RETRACTION')
Geoff Hayes on 18 Apr 2022
@Grigorios Chatziandreou - the animate_pendulum function creates a figure each time it is called which is why you will see one figure for each pendulum. Also, because of the while loop, the subsequent call to this function will be blocked until the while loop completes. If you want one figure to show all of the pendulums, then you could modify the code so that you are passing in data for each pendulum (whether you do this as an array for each input parameter, or an array of structs where each struct encapsulates the data for the pendulum, etc.) and so that each is drawn simulataneously. Alternatively, you could create a figure and maybe a timer for each pendulum whose timer callback will update the figure with the new pendulum position.
I couldn't run your code because it wasn't clear what the inputs should be (L is length, t is an array of times in seconds presumably, and theta an angle). From the code, it looks like there is an assumption that theta is an array of angles so that x and y are arrays too (so you must be calculating the angles elsewhere).
As for the other code, why not add it in as soon as you create the axes? Or does that fail for some reason?