mean value of array
조회 수: 8 (최근 30일)
이전 댓글 표시
I have one single dimension array containing doubles (A), and a 2 columns, x rows long matrix containing positions that should be applied to the single dimensioned array(B).
what i want to do is: for each row in B the 1st column and the 2column should pick values from the A array and find the mean value of the two.
So far i've used
for k=1:length(B)
C(k) = mean([A(B(k,1)) A(B(k,2))])
end
I wanted to go another way, withouth using the for loop.
somthing like:
C = mean([A(B(:,1)) A(B(:,2))])
but i dont succeed in doing it.
Do you have any sugestions?
댓글 수: 0
채택된 답변
Friedrich
2011년 8월 12일
Hi,
I think you forgot to specify the dimension. Try
C = mean([ A(B(:,1)), A(B(:,2))],2)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!