23 views (last 30 days)

Hello,

I geht this error message when I try to derive my acceleration of the car. I think there is a size problem, but I don't know how to solve it.

The data is measured from a car.

Stephen Cobeldick
on 9 Oct 2019

Edited: Stephen Cobeldick
on 9 Oct 2019

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.

One easy solution is to take the time as the mean of adjacent time points, e.g.:

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

Stephen Cobeldick
on 10 Oct 2019

"What is end and what do you mean with it?"

end is the index of the last element in that vector.

Because end is the index of the last element, end-1 is the index of the second-to-last element. Thus

meas.acc.time(1:end-1)

uses basic MATLAB indexing to return a subvector of meas.acc.time, from its first element to its second-to-last element. Thus the subvector has one fewer element than meas.acc.time, and therefore exactly the same number of elements as the output of diff.

"How do you get the average adjacent time points?"

Simply by using the definition of arithmetic mean of two values:

which is commonly written as (val1 + val2) / 2

Compare with my answer, which has the form (vec1 + vec2) ./ 2 , where vec1 is the subvector from the first element to the second-to-last element, and vec2 is the subvector from the second element to the last element. Then these two vectors are added together (i.e. corresponding elements are summed), and then divided by two to give the arithmetic mean.

V % [a,b,c,d,e]

V(1:end-1) % [a,b,c,d]

V(2:end) % [b,c,d,e]

V(1:end-1)+V(2:end) % [a,b,c,d]+[b,c,d,e] = [a+b,b+c,c+d,d+e]

(V(1:end-1)+V(2:end))/2 % [a+b,b+c,c+d,d+e]/2 = [(a+b)/2,(b+c)/2,(c+d)/2,(d+e)/2]

Tip: to use MATLAB you need to learn how to use indexing, and work with vectors/arrays.

Note that you do no have to use the arithmetic mean. As I wrote in my answer, only you can decide if such an averaging is appropriate, or if another type of averaging would be better.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.