How to avoid for loop when indexing?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mantas Vaitonis
il 2 Lug 2018
Commentato: Mantas Vaitonis
il 2 Lug 2018
Hello,
I have the following for loop, where pairs(500x10), is there to calculate cc without for loop?
for i=1:500
cc(i,:)=pairs(i,pairs(i,:));
end
4 Commenti
Stephen23
il 2 Lug 2018
@Mantas Vaitonis: given that pairs contains non-integer values, what do you expect
pairs(i,pairs(i,:));
to do?
Risposta accettata
Jan
il 2 Lug 2018
Modificato: Jan
il 2 Lug 2018
s = size(pairs);
index = sub2ind(s, repmat((1:s(1)).', 1, s(2)), pairs)
cc = pairs(index)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!