% Load coordinates from Excel file
filename = 'your_excel_file.xlsx';
data = xlsread(filename);
% Assuming the data is organized as follows:
% Each row represents a timestep
% Each column pair represents the x and y coordinates of a link
% Example: [x1, y1, x2, y2, ..., xn, yn]
[numSteps, numCols] = size(data);
numLinks = numCols / 2;
% Create a figure
figure;
hold on;
% Initialize plot with initial positions
h = gobjects(1, numLinks); % Preallocate graphics object array
for k = 1:numLinks
% Plot each link
h(k) = plot(data(1, 2*k-1), data(1, 2*k), 'o-', 'LineWidth', 2);
end
axis equal;
axis([min(data(:))-1, max(data(:))+1, min(data(:))-1, max(data(:))+1]);
% Loop through each timestep to animate
for t = 1:numSteps
for k = 1:numLinks
% Update each link's position
set(h(k), 'XData', data(t, 2*k-1), 'YData', data(t, 2*k));
end
pause(0.1); % Pause to create animation effect
end
hold off;
Make sure to replace 'your_excel_file.xlsx' with the actual path to your Excel file. Adjust axis limits, pause duration, and other plot properties as needed.