graph of velocity against time in matlab

To graph velocity against time in MATLAB, you can follow these steps:

  1. Define an array for time and velocity:
main.m
time = [0 1 2 3 4 5];
velocity = [0 10 20 30 40 50];
53 chars
3 lines
  1. Use the plot function to create a line graph:
main.m
plot(time, velocity)
21 chars
2 lines
  1. Add axis labels and a title to the graph:
main.m
xlabel('Time (seconds)')
ylabel('Velocity (m/s)')
title('Velocity vs Time')
76 chars
4 lines
  1. Display the legend:
main.m
legend('Velocity vs Time')
27 chars
2 lines

The complete code would look like this:

main.m
time = [0 1 2 3 4 5];
velocity = [0 10 20 30 40 50];

plot(time, velocity)
xlabel('Time (seconds)')
ylabel('Velocity (m/s)')
title('Velocity vs Time')
legend('Velocity vs Time')
178 chars
9 lines

This will create a graph that shows the velocity vs time.

related categories

gistlibby LogSnag