필터 지우기
필터 지우기

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에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by