vector - vectorize lookup in matlab 2-d matrix -


hi having trouble @ vectorizing following matlab code segment

for i=1:n;     vec(i) = mat(index(i),i); end; 

where index permutation of 1:n.

code slow in form. have checked notes on vectorization tricks in matlab no avail might missing obvious. in advance!

you can use index , 1:n relevant parts of mat.

vec = mat(index, 1:n); 

if n number of columns in mat, can do:

vec = mat(index,:); 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -