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

1 次查看(过去 30 天)
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...

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by