Replace values in an array with values from a single row in another array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Martin Rios
am 6 Sep. 2017
Beantwortet: Guillaume
am 6 Sep. 2017
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.
0 Kommentare
Akzeptierte Antwort
Guillaume
am 6 Sep. 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!