Replace values in an array with values from a single row in another array

조회 수: 1 (최근 30일)
I have two arrays, A of size 96*183106 and B of size 1298*121. Array B is filled with indices of data from array A that I'm interest in. I want to replace all the values in array B with data from the first row only of array A. In other words, each value in B is a specific index of the first row of array A that I want to extract. Given the difference in dimensions I'm guessing I'll have to transform one these arrays but I'm at loss on how to reach my end goal. If anyone could give me some pointers in the right direction I would appreciated it.

채택된 답변

Guillaume
Guillaume 2017년 9월 6일
A(sub2ind(size(A), repmat(1, size(B)), B)) %the 1 stands for row 1.
is all that is needed.
This will give you the values in an array the same size as B. You can reshape that in any form you want.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by