How to replace a for loop with a nested if-else condition, to get more velocity
Mostra commenti meno recenti
I have a huge vector, and time does matter to my application. I'd like to know how to gain velocity in a code simillar to the shown below (but of course, it is much more complex than this example) :
z = randi(3000);
tic
for i = 1:length(z)
if z(i) <= 15
z(i) = [];
% do something else ...
end
end
toc
1 Commento
Rik
il 3 Giu 2022
z(z<=15)=[]; will do the same as your loop. How to vectorize code depends strongly on the details of what you want to do.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements 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!