Gistlib Logo

gistlib

write a function that calculates the distance traveled in a straight line; inputs times and a vector of velocity values at the corresponding times and outputs total distance traveled as a scalar in matlab

main.m
function totalDistance = calculateDistance(times, velocities)
    totalTime = times(end) - times(1);
    totalDistance = trapz(times, velocities) * totalTime;
end
163 chars
5 lines

similar matlab code snippets

plot leonard jones formula in matlab
calculate takeoff distance in matlab
calculate final velocity with initial velocity and time in matlab
calculate velocity in matlab
how to calculate the velocity of an object in matlab
find velocity with time and initial velocity in matlab
how to find final velocity using initial velocity and time in matlab
implement a matlab function that takes time , and as inputs and returns acceleration, , velocity, , and displacement, . write your function so that it works also when is a vector of values. in matlab
how to calculate the velocity of an object in meters per second in matlab
how to calculate the speed of an object in matlab

related categories

matlab
distance
velocity

gistlibby LogSnag