How do I apply a function in accumarray that calls another variable

10 ビュー (過去 30 日間)
Prodip Das
Prodip Das 2019 年 3 月 22 日
コメント済み: Prodip Das 2019 年 3 月 25 日
So I've recently started using accumarray and to my delight it has solved many of my problems. Here's the latest one I'm kindof stuck with presently.
I have two vectors (fairly large) X and T (X being the position and T being the time-step)
I have binned X using accumarray and from what I understand, each bin gets a number of elements from X to which accumarray then applies a @fun resulting in a scalar value for that bin. I've used @mean, @sum etc up until now, but the current problem asks for more.
What I need to do now is for each subset of array X that falls into each bin,
(a) fit a 2nd order polynomial using the corresponding T values
(b) take a derivative, find the 2nd coefficient (i.e velocity in this case -> dx/dt) and out that resulting scalar in each bin. As of now solution to (a) would give me a lead.
My current line of thought is going towards a nested accumarray, is that even possible? Any directions would be helpful. Please feel free to ask me for further clarification if I haven't clearly explained the problem.
  1 件のコメント
Guillaume
Guillaume 2019 年 3 月 23 日
Can you give a short example of inputs and desired outputs.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 3 月 23 日
Nth = @(v,N) v(N);
output = splitapply(@(t,x) Nth(polyder(polyfit(t, x, 2))),2), T, X, bin_number)
  1 件のコメント
Prodip Das
Prodip Das 2019 年 3 月 25 日
Thank you! This seems to have set me in the right direction.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by