Error using interp1>reshapeAndSortXandV (line 424) X and V must be of the same length.
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Megan
el 9 de Oct. de 2019
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.
0 comentarios
Respuesta aceptada
Stephen23
el 9 de Oct. de 2019
Editada: Stephen23
el 9 de Oct. de 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;
6 comentarios
Stephen23
el 10 de Oct. de 2019
Editada: Stephen23
el 10 de Oct. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!