indexing takes a very long time
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi
i have a large multi dimentional matrix that i need to iterate pixel by pixel, lets say size(A) = [2000,2000,100];
each pixel that i iterate through i take it's neighbourhood .
btw, to my appication I have to iterate by for loop.
the problem: indexing , for example
b = A(i:i+10,i+i+10,:)
takes a very long time for some reason.
i performed timing with profiler and that line is the most expensive one (timely wise).
why is indexing such an expensive operation? is there another way to do this?
thanks
8 commentaires
Réponses (1)
Matt J
le 11 Août 2019
Modifié(e) : Matt J
le 11 Août 2019
It takes a long time because every time you execute the line
b = A(i:i+10,i+10,:)
memory is allocated for b. Instead of iterating over image neighborhoods in Mcode, you should try to write your operations in terms of use built-in functions like convn, which can access the neighborhoods in a more economical way.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!