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

elements in one matrix w.r.t max position in anothermaxtwo matrices

Hi, I have matrices A(100×96) and B(100×96). 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 1×96 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.

Best Answer

arrayfun(@(j,f) A(j,f), J,1:size(A,2))