How to remove items from two arrays that index each other without for loop
Mostra commenti meno recenti
This is hard to explain in words. Here's my code, and I'd like to know whether there's a way to vectorize the part with a for loop:
t = [obj.network.node(obj.posIx).type];
mPosIx = obj.posIx (t == 13 | t == 9);
mIxPos = zeros (1, max (mPosIx));
for idx = 1:length(mPosIx)
mIxPos (mPosIx (idx)) = idx;
end
This code does exactly what I need it to do. It removes all items that aren't type 9 or 13. The mPosIx array points to the correct position in the node array. The mIxPos array either contains a zero where there is no corresponding element in the position array (which does not appear in this code), or it contains the correct index in the position array. The for loop just feels clunky, but I couldn't figure out another way to do it.
4 Commenti
madhan ravi
il 23 Ott 2018
provide your datas to test
Al in St. Louis
il 23 Ott 2018
madhan ravi
il 23 Ott 2018
what do you mean by this?
mIxPos (mPosIx (idx)) = idx;
Al in St. Louis
il 23 Ott 2018
Risposta accettata
Più risposte (1)
Al in St. Louis
il 23 Ott 2018
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!