The Code Runs Too Long, Should I Abort It?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ashvin Hamzah Driwantara
le 14 Déc 2016
Modifié(e) : Adam
le 14 Déc 2016
I run this code and I think it runs too long. Any solution?
c6 and c3 is matrix with 3300x2200 grids.
if true
e=0.06+c6;
f=c3;
[m,n]=size(f);
for i=1:m;
for j=1:n;
if f(i,j)>e;
t(i,j) = 1;
else
t(i,j) = 0;
end
end
end
end
0 commentaires
Réponse acceptée
Adam
le 14 Déc 2016
Modifié(e) : Adam
le 14 Déc 2016
Can't you just replace the whole thing with:
t = c3 > e;
or
t = double( c3 > e );
if you want the 0s and 1s as doubles rather than logicals?
doc vectorization
gives an introduction to this very powerful alternative to nested for loops which is almost always noticeably faster too.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!