0
$\begingroup$

Could someone explain me this code?

meas.jerk.time = (meas.acc.time(1:end-1) + meas.acc.time(2:end)) ./ 2;

Assuming that meas.acc.data and meas.acc.time are vectors with the same number of elements, then diff on the data vector will return a numeric vector with one element fewer than the time vector, so meas.jerk.data and meas.jerk.time will likely have mismatching sizes.

But idk the syntax of this code. What does (1:end-1) mean or (2:end) ./2?

$\endgroup$

1 Answer 1

2
$\begingroup$

Matlab has a lot of array indexing tools. If v is a vector, then v(1:end-1) gives you the first through the second last elements of v, and v(2:end) gives the second through the last elements.

For more information on this, see the help page: https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html.

Furthermore, the ./operator stands for "element-wise right division" --, so v ./ 2 will divide every element of v by 2.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .