Error using interp1>reshapeAndSortXandV (line 424) X and V must be of the same length.
14 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
Stephen23
2019 年 10 月 9 日
編集済み: Stephen23
2019 年 10 月 9 日
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 件のコメント
Stephen23
2019 年 10 月 10 日
編集済み: Stephen23
2019 年 10 月 10 日
"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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!