compute the mean position xm between 0 and 100 seconds & find the largest time step dtm that satisfies this condition xabs(xm)< 0.027 s. in matlab

Assuming that we have the position values stored in a column vector pos and the time values stored in a column vector time, we can compute the mean position xm as follows:

main.m
tmin = 0;
tmax = 100;
idx = find(time >= tmin & time <= tmax);
pos_in_range = pos(idx);
xm = mean(pos_in_range);
113 chars
6 lines

To find the largest time step dtm that satisfies the condition xabs(xm) < 0.027, we need to find the maximum time step between any two consecutive time values in the range [tmin, tmax]. We can do this using the diff function and taking the maximum of the absolute values of the resulting array:

main.m
dt = diff(time(idx));
dtm = max(abs(dt));
42 chars
3 lines

Note that we're computing the absolute values of the time step array because we're interested in the maximum step size, regardless of whether it's positive or negative.

related categories

gistlibby LogSnag