# Extracting elements from a matrix based on the maximum position in another matrix

조회 수: 2(최근 30일)
답변: José-Luis 2017년 8월 18일
Hi, I have matrices A(100x96) and B(100x96). My aim is to find the value of element in A corresponding to position of max in B. [M, J]=max(B); % M gives max values and J gives position corresponding to max value of B. M & J have 1x96 dimension. Now I have to find values of A for position J. I know if manually I do like, A(J(1),1), A(J(2),2).. would give me required elements of A (but not suitable for large dimension). How to solve?Any suggestions. Thank you so much.

댓글을 달려면 로그인하십시오.

### 채택된 답변

KL 2017년 8월 18일
arrayfun(@(j,f) A(j,f), J,1:size(A,2))
##### 댓글 수: 1표시 없음숨기기 없음
Thank you so much.

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

José-Luis 2017년 8월 18일
a = rand(100,96);
b = rand(100,96);
[~,idx] = max(b);
result = a(sub2ind(idx,1:size(a,2)))

댓글을 달려면 로그인하십시오.

### 범주

Find more on Smoothing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!