when doing A(B)=C, get average C values if index is used >1 times
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Neubauer
el 2 de Nov. de 2022
Comentada: Daniel Neubauer
el 4 de Nov. de 2022
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!
0 comentarios
Respuesta aceptada
Walter Roberson
el 2 de Nov. de 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...
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!