フィルターのクリア

when doing A(B)=C, get average C values if index is used >1 times

1 回表示 (過去 30 日間)
Daniel Neubauer
Daniel Neubauer 2022 年 11 月 2 日
コメント済み: Daniel Neubauer 2022 年 11 月 4 日
say I have matrices
A = [0 0 0]
B=[1 1 2 3]
C=[10 20 30 40]
conventionally when doing
A(B)=C
I get
A = [20 30 40]
So by having a repeating index in B, the lowermost occurence of the index is uesd.
now what I need in this case is to get
A= [mean(C(1),C(2)) C(3) C(4)]
or alternatively another function such as min, max, etc.
So basically what I need is instead of always getting the last called index I need a function of all same called indices.
hope its possible to understand my problem. the real data i have is much bigger and the indices change iteratively, thus manually writing what I need is no option.
thanks for any help!

採用された回答

Walter Roberson
Walter Roberson 2022 年 11 月 2 日
Caution: if you are using a function that operates along the first non-singular dimension, such as mean() does, then be sure to specify the dimension at the time of calling the function if you are expecting to work by columns . mean() of a N x M matrix is 1 x M unless N == 1 in which case that is mean() of a vector and would return a scalar...
  1 件のコメント
Daniel Neubauer
Daniel Neubauer 2022 年 11 月 4 日
this looks exactly like what I need - thanks a lot!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by