plot trajectory based off x and y velocities in matlab

To plot a trajectory based off X and Y velocities in MATLAB, you can use the quiver function to visualize the velocities at each point in the trajectory and then use the plot function to connect the points and complete the trajectory. Here's an example code snippet:

main.m
% Define X and Y velocities as arrays
Xvel = [0, 1, 2, 3, 4];
Yvel = [0, 0.5, 1, 1.5, 2];

% Initialize position arrays
Xpos = zeros(size(Xvel));
Ypos = zeros(size(Yvel));

% Calculate positions from velocities
for i = 2:length(Xvel)
    Xpos(i) = Xpos(i-1) + Xvel(i);
end
for i = 2:length(Yvel)
    Ypos(i) = Ypos(i-1) + Yvel(i);
end

% Plot the trajectory
figure
quiver(Xpos, Ypos, Xvel, Yvel)
hold on
plot(Xpos, Ypos)
xlabel('X position')
ylabel('Y position')
legend('Velocity', 'Trajectory')
496 chars
25 lines

In this example, Xvel and Yvel represent the X and Y component velocities at each point in the trajectory, respectively. The Xpos and Ypos arrays are initialized to zeros and then filled in using the velocities to calculate the positions at each point. The quiver function is used to visualize the velocities at each point, while the plot function is used to connect the points and complete the trajectory. Finally, labels and a legend are added to the plot for clarity.

gistlibby LogSnag