Do not understand 'accumarray' command in Maltab

7 ビュー (過去 30 日間)
Tan Phan
Tan Phan 2016 年 8 月 16 日
回答済み: micholeodon 2017 年 12 月 15 日
Hi everybody,
I think you know about command "accumarray" in Matlab. That command is not supported in HDL Coder( convert code Matlab to VHDL). So, I try to write down another function which is same purpose with "accumarray".
Firstly, I must understand how "accumarray" is run in its documentary.
I understand the way it works with 1- column matrix subs (subs is variable of accumarray - accumarray(subs, val)). But with 2- column matrix subs , I really do know how it is running.
Example:
With matrix subs = [1 2 3 1 2 4] (only first column), I can get the number array 205-207-103-106.
But when adding with the rest column, I do not know how it is working, and how to get those number position.
Thank you for your reading!
  1 件のコメント
An Nguyen
An Nguyen 2016 年 8 月 16 日
(1,1) -> 101 + 104 ---- (2,2) -> 102 + 105 ---- (3,2) -> 103 ---- (4,1) -> 106 ---- others -> 0

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

採用された回答

Star Strider
Star Strider 2016 年 8 月 16 日
It is something of a challenge to figure out when your first encounter it, but when you think about it and work with it, it’s not all that difficult to understand.
In this example, rows 1 and 4 in ‘subs’ are both (1,1). They correspond to rows 1 and 4 in ‘val’, those being 101 and 104. The function takes those values, adds them, (or ‘accumulates’ them), and puts that value, 205 in the (1,1) position in the output matrix. The ‘subs’ argument does not define the (1,2) position anywhere, so that element remains at 0. The others work the same way.
This isn’t a full explanation, but it should get you started in understanding an extremely useful function.
  2 件のコメント
Tan Phan
Tan Phan 2016 年 8 月 16 日
Thanks so much, Star Strider! I understand it now, you have good view about it.
Star Strider
Star Strider 2016 年 8 月 16 日
My pleasure!
I use it frequently. It has many other uses as well, so I encourage you to experiment with it to understand everything it can do.

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

その他の回答 (1 件)

micholeodon
micholeodon 2017 年 12 月 15 日
I like to think it that way:
  • subs is a set of points in some space (each row corresponds to one point)
  • val are values of some Multivalued function evaluated at these points: each row contains a value at point in subs in the same row.
accumarray just sums up values of the function at each point and return a matrix (e.g. (2,1) entry is equal sum of multivalue function values at point (2,1) ).

カテゴリ

Help Center および File ExchangePulse and Transition Metrics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by