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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Guillaume
Guillaume il 6 Set 2017
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.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by