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

1 Ansicht (letzte 30 Tage)
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Nov. 2022
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...

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by